属性的格式如下:

$.fn.attr

该格式既可以获取属性的值也可以设置属性的值。示例如下:

设置属性

1 // Setting attributes
2 $("a").attr( "href", "allMyHrefsAreTheSameNow.html" );
3 $("a").attr({
4 title: "all titles are the same too!",
5 href: "somethingNew.html"
6 });

获取属性

1 // Getting attributes
2 $("a").attr("href"); // returns the href for the first a element in the document

 

相关文章:

  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2021-06-09
  • 2021-07-03
  • 2022-01-06
猜你喜欢
  • 2021-10-08
  • 2021-09-03
  • 2022-12-23
  • 2021-09-28
  • 2021-05-18
  • 2021-08-09
  • 2021-10-01
相关资源
相似解决方案