程式碼
html
<input name="mycheckbox[]" type="checkbox" value="1" />1
<input name="mycheckbox[]" type="checkbox" value="2" />2
<input name="mycheckbox[]" type="checkbox" value="3" />3
<input name="mycheckbox[]" type="checkbox" value="4" />4
<input type="button" id="get_chk_value" value="Get" />
<div id="chk_val"></div>
js
$(function(){
$('#get_chk_value').click(function(){
var val_arr = [];
$(':checkbox:checked').each(function(i){
val_arr[i] = $(this).val();
});
$('#chk_val').html(val_arr.join('<br>'));
});
});
留言
張貼留言