爱程序网

jquery如何修改连接a的href属性值

来源: 阅读:

jquery如何修改连接a的href属性值:
有时候可能需要动态的修改超链接的指向地址,下面通过代代码实例简单的介绍一下。
代码实例如下:

 

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>蚂蚁部落</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#bt").click(function(){
    $("#theLink").attr("href","http://www.softwhy.com"); 
        $("#theLink").text("蚂蚁部落"); 
  })
})
</script>
</head>
<body>
<a href="www.163.com" id="theLink">网易</a>
<input type="button" id="bt" value="改变地址"/>
</body>
</html>

 

以上代码实现了我们的要求,代码比较简单,这里就不多介绍了,具体可以参阅相关阅读。
相关阅读:
1.click事件可以参阅jQuery的click事件一章节。
2. attr()函数可以参阅jQuery的attr()方法一章节。 
3.text()函数可以参阅jQuery的text()方法一章节。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=11307

更多内容可以参阅:http://www.softwhy.com/jquery/

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助