宝哥软件园

jquery复选框的相关操作总结

编辑:宝哥软件园 来源:互联网 时间:2021-09-07

jquery复选框的相关操作——全选、反选、获得所有选中的检验盒

1、全选

$('#btn1 ').单击(function(){ $(' input[name=' checkbox ']').attr('checked ',' true ');}) 2、取消全选(全不选)

$('#btn2 ').单击(function(){ $(' input[name=' checkbox ']').removeAttr(“”选中');}) 3、选中所有奇数

$('#btn3 ').单击(function(){ $(' input[name=' checkbox ']: odd ').attr('checked ',' true ');}) 4、选中所有偶数

$('#btn6 ').单击(function(){ $(' input[name=' checkbox ']: even ').attr('checked ',' true ');}) 5、反选

$('#btn4 ').单击(function(){ $(' input[name=' checkbox ']').每个(函数(){ if($(this)).attr('选中){ $(这个).removeAttr(“”选中');} else { $(this).attr('checked ',' true ');} }) }) 或者

$(' # invent ').单击(function(){ $(' # rule message[name=' DelModuleid ']: checkbox ').每个(函数(I,o){ $(o)).attr('选中',美元.attr('选中');});});6、获取选择项的值

var aa=$('#btn5 ').单击(function(){ $(' input[name=' checkbox ']: checkbox :已选中').每个(函数(){ aa=$(this)).val()})文档。写(aa);}) })7、遍历选中项

$("输入[类型=复选框][选中])。每个(函数(){ //由于复选框一般选中的是多个,所以可以循环输出警报($(本)).val());});8、例子

html xmlns=' http://www。w3。org/1999/XHTML ' head runat=' server ' title无标题页/title脚本src=' http : js/jQuery-1.6。量滴js ' type=' text/JavaScript '/script script type=' text/JavaScript ' jQuery(函数($){//全选$('#btn1 ').单击(function(){ $(' input[name=' checkbox ']').attr('checked ',' true ');}) //取消全选$('#btn2 ').单击(function(){ $(' input[name=' checkbox ']').removeAttr(“”选中');}) //选中所有基数$('#btn3 ').单击(function(){ $(' input[name=' checkbox ']: even ').attr('checked ',' true ');}) //选中所有偶数$('#btn6 ').单击(function(){ $(' input[name=' checkbox ']: odd ').attr('checked ',' true ');}) //反选$('#btn4 ').单击(function(){ $(' input[name=' checkbox ']').每个(函数(){ if($(this)).attr('选中){ $(这个).removeAttr(“”选中');} else { $(this).attr('checked ',' true ');} }) }) //或许选择项的值var aa=$('#btn5 ').单击(function(){ $(' input[name=' checkbox ']: checkbox :已选中').每个(函数(){ aa=$(this)).val()})文档。写(aa);})}))/脚本/标题正文表单id='form1' runat='server' div输入类型='button' id='btn1' value='全选输入类型='button' id='btn2 '值='取消全选输入类型='button' id='btn3 '值='选中所有奇数输入类型='button' id='btn6 '值='选中所有偶数输入类型='button' id='btn4 '值='反选输入类型='button' id='btn5 '值='获得选中的所有值英国铁路公司输入类型=“复选框”名称=“复选框”值=“复选框1”复选框1输入类型=“复选框”名称=“复选框2”复选框2输入类型=' checkbox ' name=' checkbox ' value=' checkbox ' name=' checkbox ' value=' checkbox 4 ' checkbox 4输入类型='复选框'名称='复选框值=“复选框5”复选框5输入类型=“复选框”名称=“复选框”值=“复选框6”复选框6效果图

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

更多资讯
游戏推荐
更多+