zoukankan      html  css  js  c++  java
  • JQUERY prop与attr差额

    1.  1-9-1之前和之后之间的差

    <html>
    <script src="Js/jquery-1.9.0.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){
     $(":button").click(function(){
     //prop与attr差别 
     //attr在1.9以后attr没有初始化的.attr("checked")返回都是undefined 
     console.log("prop1="+$(":checkbox:eq(0)").prop("checked"));
     console.log("attr1="+$(":checkbox:eq(0)").attr("checked"));
     //attr在1.9以后attr初始化的不管是否选中.attr("checked")返回都是checked
     console.log("prop2="+$(":checkbox:eq(1)").prop("checked"));
     console.log("attr2="+$(":checkbox:eq(1)").attr("checked"));
    })
    
    })
    </script>
    <body>
    <input type="button" value="bt" id="bt"/>
    <input type="checkbox" id="ck" value="1" /><label>1</label>
    <input type="checkbox" id="ck" value="2" checked="checked"/><label>2</label>
    </body>
    </html>
    


    2.  使用方法

    //3种
    .attr("name");
    .attr("name","value");
    .attr({"name":"value"})
    //4种
    .prop("name");
    .prop("name","value");
    .prop({"name":"value"})
    .prop("checked",function(){
            return true;
    })


     

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    三种省市级联下拉列表的写法
    三种省市级联下拉列表的写法
    SQL经典试题(mysql)
    60行代码俄罗斯方块
    ibatis xml中配置信息详解
    60行代码俄罗斯方块
    xinetd
    csh and tcsh
    xinetd restart
    bash sh
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4752281.html
Copyright © 2011-2022 走看看