最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Double execution on a single click jquery - Stack Overflow

programmeradmin4浏览0评论

i am having a problem when i click on an input(button) (click event captured using jquery) it is executed two times but the click event is single... i used "e.stopPropagation();" - but it didn't work...

jQuery("#ok").click(function(e){
       alert("Alert");
       e.stopPropagation();
});

i need the reason and the solution...

take care..

i am having a problem when i click on an input(button) (click event captured using jquery) it is executed two times but the click event is single... i used "e.stopPropagation();" - but it didn't work...

jQuery("#ok").click(function(e){
       alert("Alert");
       e.stopPropagation();
});

i need the reason and the solution...

take care..

Share Improve this question edited Dec 28, 2010 at 7:46 Jamal Abdul Nasir asked Dec 28, 2010 at 7:21 Jamal Abdul NasirJamal Abdul Nasir 2,6675 gold badges31 silver badges47 bronze badges 3
  • 1 post your code...so that we can understand whats going on... – Vivek Commented Dec 28, 2010 at 7:23
  • May be you somehow ran this click-setup code twice? – Maxim Sloyko Commented Dec 28, 2010 at 8:06
  • @maksymko... no brother just once.. – Jamal Abdul Nasir Commented Dec 28, 2010 at 8:14
Add a ment  | 

5 Answers 5

Reset to default 10

problem is solved...

i just added e.stopImmediatePropagation(); to the click function... and it worked... None of the following functions worked...

e.preventDefault();
e.stopPropagation();
return false

---------------------CODE---------------------

jQuery("#ok").click(function(e){
       alert("Alert");
       e.stopImmediatePropagation();
});

Click here for more information on jQuery Events..

Please use e.stop(true,true) and function which you are using. like

e.stop(true,true).show();

I think you use this code as below:

jQuery("#ok").click(function(){
   alert("Alert");
   return false;

});

e.preventDefault() is likely what you are looking for.

i used

return false;

after the desired action.

发布评论

评论列表(0)

  1. 暂无评论