使用js和jQuery写一个全选的案例
效果图:
html代码:
<input type="button" value="全选">
<input type="button" value="全不选">
<input type="button" value="反选">
<br />
<input type="checkbox" name="s">春
<br />
<input type="checkbox" name="s">夏
<br />
<input type="checkbox" name="s">秋
<br />
<input type="checkbox" name="s">冬
jQuery代码:
$(function(){
$(":button:eq(0)").click(function(){
$(":checkbox").prop(“checked”,true);
})
$(":button:eq(1)").click(function(){
$(":checkbox").prop(“checked”,false);
})
$(":button:eq(2)").click(function(){
$(":checkbox").each(function() {
var flag = $(this).prop(“checked”);
$(this).prop(“checked”, !flag);
})
})
})
第二种方法:js和jQuery并用
<input type="button" value="全选" "quan();">
<input type="button" value="全不选" "bu();">
<input type="button" value="反选" "fan();">
<br />
<input type="checkbox" name="s">春
<br />
<input type="checkbox" name="s">夏
<br />
<input type="checkbox" name="s">秋
<br />
<input type="checkbox" name="s">冬
就只会这两种方法,如果有大佬会更简单的希望教教我!