可以先體驗一下效果:http://keleyi.com/keleyi/phtml/jquery/2.htm
以下修改a標簽的href鏈接和修改文字的代碼:
<script type="text/javascript" src="http:/keleyi.com/keleyi/pmedia/jquery-1.9.1.min.js"></script>
原鏈接:
<a href="http://keleyi.com" id="home_keleyi_com">柯樂義</a>
修改a標簽的href鏈接:
$('#home_keleyi_com').attr('href','http://keleyi.com');
修改文字:
$("#home_keleyi_com").text('柯樂義首頁');
修改后的鏈接為:
<a href="http://keleyi.com" id="home_keleyi_com">柯樂義首頁</a>
下面是完整代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery修改鏈接--柯樂義</title>
<script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery-1.9.1.min.js"></script>
</head>
<body>
jquery修改a標簽的href鏈接和文字,先點擊下面鏈接<br />然后點擊"改變"按鈕,然后點點擊一次下面的鏈接,注意兩次打開頁面的不同:<br />
<a href="http://keleyi.com/a/bjac/d863921ed93d03ff.htm" id="home_keleyi_com" target="_blank">原文</a> <input type="button" value="改變" id="gb_keleyi_com" />
<script type="text/javascript">
$("#gb_keleyi_com").bind("click",function (){
$('#home_keleyi_com').attr('href','http://keleyi.com');
$("#home_keleyi_com").text('柯樂義首頁');})
</script>
</body>
</html>
參考:http://hovertree.com/hvtart/bjae/c5a746a2d25d43b7.htm
