1.9以后Jquery不支持attr啦!

来源:互联网 发布:seo能自学吗 编辑:程序博客网 时间:2024/04/30 06:56
<script type="text/javascript">    $(function () {        $("#chckAll").click(function () {                               //$("input[name='chckList']").attr("checked", $("#chckAll").attr("checked"));   失败!            var flag = $(this).prop("checked");            alert(flag);            if (!flag) {                $("[name = 'chckList']:checkbox").attr("checked", false);            }            else {                $("[name = 'chckList']:checkbox").attr("checked", true);            }                });    });</script>


今天jquery1.5升级1.9,发现
<input type="text" name="test" id="test" />
居然用attr("value")取到的值为"",改用val()才能获得我所填的值.
重写html为
<input type="text" name="test" id="test" value="123"/>
发现attr("value")=123 (永远是html页面中写的value值), 而val()=所填的值. (文本框中填的值) from 1.9.0 开始

attr() 取html文档中的属性,prop()取js dom对象的属性,

allt() 可以设置html文档的属性,但不能获取html文档中没有设置的属性的值

用attr()和prop()设置checked,disabled,selected等的值,最好用true和false


0 0
原创粉丝点击