实例 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/");
  });
});
</script>
</head>
<body>
<p><a href="https://cankaoshouce.com" id="ca">cankaoshouce.com</a></p>
<button>Change href Value</button>
<p>Mouse over the link (or click on it) to see that the value of the href attribute has changed.</p>
</body>
</html>
                    

输出结果