有时候,只希望网站某个链接只能被点击一次,怎么做呢?下面给出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

相关文章:

  • 2021-08-06
  • 2021-06-27
  • 2022-12-23
  • 2021-06-18
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
猜你喜欢
  • 2022-01-13
  • 2022-12-23
  • 2021-11-22
  • 2021-12-10
  • 2022-12-23
  • 2021-12-10
  • 2021-06-04
相关资源
相似解决方案