ITPub博客

首页 > IT职业 > IT生活 > jquery-checkbox的属性选择判断

jquery-checkbox的属性选择判断

IT生活 作者:daifan 时间:2021-09-09 10:02:02 0 删除 编辑

------------------------------------------------------
checkbox的属性选择判断:

<script type="text/javascript">$(function(){alert("start");alert($(".parentchack").attr("checked"));if($(".parentchack").attr("checked")=="checked"){    alert("true");}else{    alert("false");};});</script>

-------------------------------------------------------
这样会选择所有clas=“parentcheck”的元素后面元素,而且不管是第几个.parentcheck触发的事件,都以第一个.parentcheck中的值为参考

<script type="text/javascript">function(){if($(".parentcheck").attr("checked")=="checked"){    $(".parentcheck").parent().next().children().attr("checked",true);}else{    $(".parentcheck").parent().next().children().attr("checked",false);} }</script>

-------------------------------------------------------
一个正确的checkbox选择,传递进来的是body里面的onclick="pcheck(this)",表示当前元素,即下面的fckeck:

<script type="text/javascript">function pcheck(fcheck){if(fcheck.checked){    alert("true");    $(fcheck).parent().next().children().attr("checked",true);}else{    alert("false");    $(fcheck).parent().next().children().attr("checked",false);}}</script>

------------------------------------------------------

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2311/viewspace-2815431/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-16

  • 博文量
    96
  • 访问量
    810