实例 jQuery attr() - 设置多个属性值

x
 
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#ca").attr({
      "href" : "https://cankaoshouce.com/jquery/",
      "title" : "jQuery Tutorial"
    });
  });
});
</script>
</head>
<body>
<p><a href="https://cankaoshouce.com" title="some title" id="ca">cankaoshouce.com</a></p>
<button>Change href and title</button>
<p>Mouse over the link to see that the href attribute has changed and a title attribute is set.</p>
</body>
</html>
                    

输出结果