zoukankan      html  css  js  c++  java
  • 解决单选按钮存在属性为checked却没有选中的问题

    我在编辑以下代码时,发现单选按钮(即.radio)在设置checked属性后,会出现开发者工具中Elements中有checked值,但是单选按钮却没有选中的问题。

    $('.allSelectRadio').click(()=>{
        if($('.allSelectRadio').attr('checked')){
            $('.allSelectRadio').removeAttr('checked')
            $('.radio').removeAttr('checked')
        }else{
            $('.allSelectRadio').attr('checked',true)
            $('.radio').attr('checked',"checked")
        }
    })

    解决方法:把attr改成prop即可。

    $('.allSelectRadio').click(()=>{
        if($('.allSelectRadio').attr('checked')){
            $('.allSelectRadio').removeAttr('checked')
            $('.radio').removeAttr('checked')
        }else{
            $('.allSelectRadio').attr('checked',true)
            $('.radio').prop('checked',"checked")
        }
    })
  • 相关阅读:
    观光公交
    luogu 4779 【模板】
    最小生成树(luogu 3366)
    计算系数
    更新区间,求单点—— luogu 3368
    HDU
    HDU
    HDU
    HDU
    BFS
  • 原文地址:https://www.cnblogs.com/luoyihao/p/14917752.html
Copyright © 2011-2022 走看看