本文實例講述了jQuery使用attr()方法同時設置多個屬性值的用法。分享給大家供大家參考。具體如下:
下面這個演示例子可通過點擊按鈕實現修改鏈接與提示的功能。
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#w3s").attr({
"href" : "http://www.cnblogs.com/list/list_172_1.htm",
"title" : "cnblogs.com"
});
});
});
</script>
</head>
<body>
<p><a href="http://www.cnblogs.com/list/list_172_1.htm" id="w3s">cnblogs.com</a></p>
<button>點此改變鏈接與提示</button>
<p>鼠標滑過鏈接即可看到鏈接與提示信息已被更改.</p>
</body>
</html>
希望本文所述對大家的jQuery程序設計有所幫助。