注册 登录
编程论坛 JavaScript论坛

js更改链接地址的问题

yuhaijunll 发布于 2009-11-19 15:08, 1760 次点击
有一个链接地址为:  <a href="#">Press Here</a>

点击一次为:  <a href="1.php?sort=yes">Press Here</a>

再点击一次为: <a href="1.php?sort=no">Press Here</a>

同样,再点击一次为: <a href="1.php?sort=yes">Press Here</a>
下面就循环了。


自己写了一个,但是实现不了。

程序代码:
<a id="enjoy" href="#"  onclick="return fnGo(this);" >Click me</a>
<script>
function fnGo(o){
  o.href = '?sort=yes' ;
 document.getElementById("enjoy").onclick = 'return fnGo1(this)' ;
return true;
}

function fnGo1(b){
  b.href = '?sort=no' ;
 document.getElementById("enjoy").onclick = 'return fnGo(this)' ;
return true;
}
</script>

2 回复
#2
aspic2009-11-19 15:14
document.getElementById("enjoy").onclick = function() {你的代码}
#3
aspic2009-11-19 15:24
程序代码:
<a href="javascript:void(0)" id="test">点我呀</a>
<script>
document.getElementById('test').onclick = function() {
    this.href = (this.href == ('1.php?sort=yes'||'javascript:void(0)')) ? '1.php?sort=no' : '1.php?sort=yes';
    return false
}
</script>
空链接用#好像不好
1