首页 > Web开发 > 详细

jquery的attr和prop区别之实例

时间:2017-05-16 22:18:00      阅读:353      评论:0      收藏:0      [点我收藏+]
  • 对于HTML元素本身就带有的固有属性,在处理时,使用prop方法。
  • 对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr方法。

 

html文件

<tr>
                        <th></th>
                        <td>
                            <a class="easyui-linkbutton" style="width:60px;" onclick="selectAll()">全选</a>
                            <a class="easyui-linkbutton" style="width:60px;" onclick="unSelectAll()">全不选</a>
                        </td>
                    </tr>

 

 

JS文件

//给相同名称的CheckBox赋属性值

function selectAll(){ $(
‘input[name="groupItem"]‘).val(function(index,val){ $(this).prop(‘checked‘,true);
          //$(this).attr(‘checked‘,true);//错误
return val; }) } function unSelectAll(){ $(‘input[name="groupItem"]‘).val(function(index,val){ $(this).prop(‘checked‘,false);
//$(this).attr(‘checked‘,false);错误
return val; }) }

 

jquery的attr和prop区别之实例

原文:http://www.cnblogs.com/mr-wuxiansheng/p/6863941.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!