手机版

jquery中表单多选框的一种巧妙写法

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

!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN ' ' http://www .w3。org/TR/XHTML 1/DTD/XHTML L1-严格。DTD ' html xmlns=' http://www .w3。org/1999/XHTML ' XML : lang=' EN ' lang=' EN ' health eta http-equiv=' Content-Type ' Content=' text/html;charset=utf-8 '/title/title link href=' CSS/style。CSS ' rel='样式表type=' text/CSS '/script src=' http :/scripts/jquery-1。3 .1 .js ' type=' text/JavaScript '/script script type=' text/JavaScript ' $(function(){ $(' tbodytr : odd ')).addClass(')奇数');$('tbodytr:even ').addClass(')偶数');$('tbodytr ').单击(function(){ var hasSelected=$(this)).具有类(“选定的”);$(这个)[hasSelected?移除类别' : ' addCLaSS '](' selected ').查找(“:复选框”).attr('选中',hasSelected);});$(“tbodytr :已(选中:)”).addClass(')选定');})/脚本/标题表d tr th/th ths/th thsd/th thsdasa sda/th/tr/d t正文tr tdinput type=' checkbox ' name=' choice ' value=' '//TD TDS/TD TDS/TD TDS/TD TDS/TD tdinput type=' checkbox ' name=' choice ' value=' ' checking='实打实的速度是TD/tr/t正文/表格/正文/html

收音机写法:

$(function(){ $(' tbodytr : odd ').addClass(')奇数');$('tbodytr:even ').addClass(')偶数');$('tbodytr ').单击(function(){ $(this)).addClass(')选定')。兄弟姐妹()。removeClass(“”选定')。end().查找(' :radio ').attr('checked ',true);});//$(“表格:收音机:已检查”).父项()。父项()。addClass(')选定');$(“表格:无线电:已检查”).父母(' tr ').addClass(')选定');//$(“tbodytr :已选中(:)”).addClass(')选定');})复选框写法:

$(function(){ $(' tbodytr : odd ').addClass(')奇数');$('tbodytr:even ').addClass(')偶数');$('tbodytr ').单击(function(){ if($(this)).有类(' selected '){ $(this).removeClass(“”选定')。查找(“:复选框”).attr('checked ',false);}else{ $(this).addClass(')选定')。查找(“:复选框”).attr('checked ',true);} });//$(“表格:复选框:检查”).父项()。父项()。addClass(')选定');$(“表格:复选框:检查”).父母(' tr ').addClass(')选定');//$(“tbodytr :已选中(:)”).addClass(')选定');})

版权声明:jquery中表单多选框的一种巧妙写法是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。