我在HTML表單中有以下複選框。通過名稱選擇複選框的按鈕
<ul id="selection">
<span><label>First<br><input type="checkbox" name="First"></label></span>
<span><label>Second<br><input type="checkbox" name="Second"></label></span>
<span><label>Third<br><input type="checkbox" name="Third"></label></span>
<span><label>Fourth<br><input type="checkbox" name="Fourth"></label></span>
<span><label>Fifth<br><input type="checkbox" name="Fifth"></label></span>
</ul>
我試圖創建兩個按鈕。一個會選擇前兩個,一個選擇全部。
我設法使用這一個按鈕,選擇所有的人:
<input type="button" class="check btn" onClick="select(this)" value="Select All"/>
<script>
$('.check:button').click(function(){
var checked = !$(this).data('checked');
$('input:checkbox').prop('checked', checked);
$(this).val(checked ? 'uncheck all' : 'Select')
$(this).data('checked', checked);
});
</script>
但我似乎無法得到這兩個按鈕的工作。
我的JavaScript知識是相當有限的,一直在尋找幾天,但沒有成功的解決方案。
可以請別人幫忙嗎?詳細的解釋會很棒。
HTTP: //stackoverflow.com/questions/1107220/how-can-i-select-an-elem ENT按姓名與 - jQuery的 –