attr(properties)方法将键/值对象设置为所有匹配元素的属性。
selector.attr({property1:value1, property2:value2})
这是此方法使用的所有参数的描述-
链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/attr-properties.html
来源:LearnFk无涯教程网
property - 这是匹配元素的CSS属性。
value - 这是要设置的属性的值。
<html> <head> <title>The Selecter Example</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("img").attr({ src: "/images/jquery.jpg", title: "jQuery", alt: "jQuery Logo" }); }); </script> </head> <body> <div class="division" id="divid"> <p>Following is the logo of jQuery</p> <img src="/jquery/images/jquery-mini-logo.jpg" title="None" alt="None" /> </div> </body> </html>
这将产生以下输出-
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)