zoukankan      html  css  js  c++  java
  • jquery-1.10.2 获取checkbox的checked属性总是undefined

    项目中用的jquery-1.10.2 需要检测一个checkbox的选中状态,想当然的用 .attr("checked") ,结果发现,无论是否选中,这个值都是 undefined 未定义。

           查找资料,特此记录:

           jq官网说明:

          As of jQuery 1.6, the .attr() method returns undefined for attributes that have not been set. In addition, .attr() should not be used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use the .prop()method.

           .attr() 不能用于普通对象,数组,窗口,文档等,要重新获取改变dom属性,用.prop()方法。

            用.prop方法确实可行。

            贴一段代码如下:

    function ChangeAllIndustrySelectState() {
                var checked = $("#allIndustryCkbx").prop("checked");
                if (checked) {//选中所有行业
                    $("table input[type=checkbox]").prop("checked", true);
                } else {//取消所有行业选择
                    $("table input[type=checkbox]").prop("checked", false);
                }
            }
    

      

  • 相关阅读:
    nlogn LIS CF1437E
    CF 1444B
    unsigned int慎用
    CF1425D 容斥 组合数 快速幂求逆元
    CF 1408D探照灯 找 匪
    各种状态转移
    CF 459C
    主席树 入门
    杭州特色景致的性价比精致餐厅
    SQL函数总结
  • 原文地址:https://www.cnblogs.com/chengshuiqiang/p/4512279.html
Copyright © 2011-2022 走看看