jQuery 操作CheckBox选中,取消,取值的实现方法

前端之家收集整理的这篇文章主要介绍了jQuery 操作CheckBox选中,取消,取值的实现方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
感兴趣jQuery 操作CheckBox选中,取消,取值的实现方法的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。<br> @H_301_0@ <SCRIPT LANGUAGE="javascript" src="/jquery.js"></script> <SCRIPT LANGUAGE="javascript"> <!-- $("document.quot;).ready(function(){ $("#btn1").click(function(){ $("[name='checkBox']").attr("checked",'true');//全选 }) $("#btn2").click(function(){ $("[name='checkBox']").removeAttr("checked");//取消全选 }) $("#btn3").click(function(){ $("[name='checkBox']:even").attr("checked",'true');//选中所有奇数 }) $("#btn4").click(function(){ $("[name='checkBox']").each(function(){ if($(this).attr("checked")) { $(this).removeAttr("checked"); } else { $(this).attr("checked",'true'); } }) }) $("#btn5").click(function(){ var str=""; $("[name='checkBox'][checked]").each(function(){ str+=$(this).val()+""r"n"; //alert($(this).val()); }) alert(str); }) }) //--> </SCRIPT> </HEAD> <BODY> <form name="form1" method="post" action=""> <input type="button" id="btn1" value="全选"> <input type="button" id="btn2" value="取消全选"> <input type="button" id="btn3" value="选中所有奇数"> <input type="button" id="btn4" value="反选"> <input type="button" id="btn5" value="获得选中的所有值"> <br> <input type="checkBox" name="checkBox" value="checkBox1"> checkBox1 <input type="checkBox" name="checkBox" value="checkBox2"> checkBox2 <input type="checkBox" name="checkBox" value="checkBox3"> checkBox3 www.jbxue.com <input type="checkBox" name="checkBox" value="checkBox4"> checkBox4 <input type="checkBox" name="checkBox" value="checkBox5"> checkBox5 <input type="checkBox" name="checkBox" value="checkBox6"> checkBox6 <input type="checkBox" name="checkBox" value="checkBox7"> checkBox7 <input type="checkBox" name="checkBox" value="checkBox8"> checkBox8 </form> 

猜你在找的jQuery相关文章