event.stopPropagation()不适用于click事件

时间:2013-10-22 18:36:03

标签: jquery stoppropagation

在我的代码的一部分(非常广泛,所以我只展示适用的部分),我有这个:

$(".help."+help+" .left").click(function(event){
event.stopPropagation();
if (!moving){
  moving = 1;
  var move = $(".help."+help+" .all").css("left");
  move = parseInt(move.substr(0,move.length-2)) + 300;
  if (move <= 0)$(".help."+help+" .all").animate({left:move},{duration:300,complete:function(){moving = 0}})
  else moving = 0;
};
});

event.stopPropagation()是为了防止这被调用:

$("html").click(function(){
alert("check");
$(".help").each(function(){
  if ($(this).hasClass("open")){
    $(this).removeClass("open").animate({opacity:0},{duration:500,complete:function(){
      $(this).css("display","none");
    }});
  };
});
});

此部分用于在文档中的任何位置单击“帮助框”时关闭它。

event.stopPropagation()不起作用。我把alert("check")放在那里以确保它是问题,而且它是。

奇怪的部分?下一行代码正在使用event.stopPropagation()

$(".showhelp").click(function(event){
event.stopPropagation();
if ($(this).hasClass("materials"))help = "materials";
else help = "bearings";
if (!$(".help."+help).hasClass("open")){
  $(".help."+help).addClass("open").css("display","block").animate({opacity:1},200);
}else{
  $(".help."+help).removeClass("open").animate({opacity:0},{duration:200,complete:function(){
    $(this).css("display","none");
  }});
};
});

我希望这是足够的信息。

1 个答案:

答案 0 :(得分:1)

我意识到问题是什么。与stopPropagation()无关。与未定义的变量有关。

问题已解决。谢谢你的帮助!

相关问题