jQuery对checkbox的各种操作
发布日期:2022-02-17 04:52:17 浏览次数:16 分类:技术文章

本文共 1291 字,大约阅读时间需要 4 分钟。

 
//获取所有的checkbox$("input[type='checkbox']");$("input[name='cb']");//获取所有选中的checkbox$('input:checkbox:checked');$('input:[type='checkbox']:checked');$('input[type='checkbox']:checked');$('input:[name='test']:checked');//获取checkbox的值$('#checkbox').val();//获取多个选中的checkbox的值var vals = [];$('input:checkbox:checked').each(function(index,item){    vals.push($(this).val());});//判断checkbox是否选中 (jquery 1.6以前版本 用  $(this).attr("checked"));$('#checkbox').click(function(){    if($(this).prop('checked')){        alert('选中');        }else{        alert('没有选中');    };});//设置checkbox为选中状态$('input:checkbox').attr('checked','checked');$('input:checkbox').attr('checked',true);//设置checkbox为不选中状态$('input:checkbox').attr('checked',false);$('input:checkbox').attr('checked','');//设置checkbox为禁用状态(jquery<1.6用attr,jquery>=1.6建议用prop)$("input[type='checkbox']").attr("disabled", "disabled");$("input[type='checkbox']").attr("disabled", true);$("input[type='checkbox']").prop("disabled", true);$("input[type='checkbox']").prop("disabled", "disabled");//设置checkbox为启用状态(jquery<1.6用attr,jquery>=1.6建议用prop)$("input[type='checkbox']").removeAttr("disabled");$("input[type='checkbox']").attr("disabled", false);$("input[type='checkbox']").prop("disabled", "");$("input[type='checkbox']").prop("disabled", false);

 

转载地址:https://blog.csdn.net/qq_41427602/article/details/86571676 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:父div中生成多个子div并排并填充满父容器
下一篇:Eclipse设置Tab键缩进4个空格

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年03月30日 17时27分13秒