如何实现链接只能被点击一次

有时候,只希望网站某个链接只能被点击一次,怎么做呢?下面给出3中方法!
第一种:
利用JS在点击后把href变成#把taget变成空。

 

<p><a onclick="var that = this;setTimeout(function(){that.removeAttribute('href');that.onclick=that=null;}, 0);return true;" href="http://www.g.cn" target="_blank">Open Google in New Window</a></p>

 

 

Open Google in New Window

提示:你可以先修改部分代码再运行。

第二种:
利用JS在点击后删除href属性,使链接变为文字。兼容IE6,IE7,IE8,Firefox,Opera,Safari,Chrome

 

<p><a onclick="var that = this;setTimeout(function(){that.removeAttribute('href');that.onclick=that=null;}, 0);return true;" href="http://www.g.cn" target="_blank">Open Google in New Window</a></p>

 

 

Open Google in New Window

提示:你可以先修改部分代码再运行。

第三种:
设置href值及target值的一种做法

 

<p><a onclick="this._clk?(this.href='javascript:;',this.target='_self'):(this._clk=1);" href="http://www.google.cn" target="_blank">Open Google in New Window</a></p>

 

 

Open Google in New Window

posted @ 2010-10-08 17:54  MaxIE  阅读(2781)  评论(2编辑  收藏  举报