当前位置:Gxlcms > JavaScript > 浅谈jQuery双事件多重加载的问题

浅谈jQuery双事件多重加载的问题

时间:2021-07-01 10:21:17 帮助过:7人阅读

如下所示:

<html> 
<a href="1**.html"> 
  <button onclick="buttonEvent()">点击事件</button> 
</a> 
</html> 
function buttonEvent(){ 
  location.href = "2**.html"; 
} 

如代码显示那样,当点击button按钮的时候想跳转到2**.html页面。但是,这个最终执行的结果是,先跳转到2**.html页面,然后再跳转到1**.html页面,最终显示的结果是1**.html页面中的内容。

那么,在function中加入下面的代码才可以达到上面的目的。

function buttonEvent(e){ 
  e = e || window.event; 
  e.stopPropagation(); 
  e.preventDefault(); 
  location.href = "2**.html"; 
} 

以上就是小编为大家带来的浅谈jQuery双事件多重加载的问题全部内容了,希望大家多多支持脚本之家~

人气教程排行