您的位置:首页 > Web前端 > JQuery

jquery中的prop()和attr()方法区别

2016-11-15 19:50 399 查看
什么时候使用attr(),什么时候使用prop()?

1.添加属性名称该属性就会生效应该使用prop();

2.是有true,false两个属性使用prop();

3.其他则使用attr();

下面是官方建议使用attr和prop的使用场景

Attribute/Property                 .attr()     .prop()
accesskey                √
align                    √
async                    √             √
autofocus                √             √
checked                  √             √
class                    √
contenteditable          √
draggable                √
href                     √
id                       √
label                    √
location ( i.e. window.location )    √             √
multiple                 √             √
readOnly                 √             √
rel                      √
selected                 √             √
src                      √
tabindex                 √
title                    √
type                     √
width ( if needed over .width() )    √
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jquery attr prop