JQuery自1.6.1版本开始增加一些属性,使用时尽量使用这些新的属性,例如:selected、checked。在高版本中赋值时最好用prop,如果用attr就会出现赋值不成功的问题,

一般自定义属性用attr,固有属性用prop

以下是官方建议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() )

相关文章:

  • 2021-11-05
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2021-08-29
  • 2022-12-23
  • 2022-01-03
  • 2022-02-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2021-05-30
  • 2022-12-23
  • 2022-01-07
  • 2021-12-31
相关资源
相似解决方案