Javascript jQuery脚本冲突,两个不同的切换函数相互影响

Javascript jQuery脚本冲突,两个不同的切换函数相互影响,javascript,jquery,toggle,conflict,Javascript,Jquery,Toggle,Conflict,我有两个脚本: // Show the stats slide out $(document).on('click','.buildscore',function(){ $(".buildscore2").slideToggle(); }); // Hide / show the comments $(document).on('click','#hideshow',function(){ $('.commentsbox').toggle();

我有两个脚本:

    // Show the stats slide out
$(document).on('click','.buildscore',function(){     
    $(".buildscore2").slideToggle();
});

// Hide / show the comments
$(document).on('click','#hideshow',function(){       
    $('.commentsbox').toggle();
    $('.commentsboxhidden').toggle();
});
comments切换工作正常,buildscore也工作正常。但是buildscore统计数据滑出功能也可以切换注释框div

看看小提琴:


提前谢谢。

简单一点。简单HTML,具有唯一ID和仅必要的标记:

<input type='button' id='hideshow' value='Comments On / Off'>
<div class="commentsbox">COMMENT</div>
<input type='button' id="buildscore" value='STATS'>
<div class="buildscore">STATS</div>

元素需要有唯一的ID。您为两个按钮提供了相同的“hideshow”ID。您需要根据希望发生的事情确定元素的目标,并为它们提供适当的属性。典型。我想了好几个小时。。。把它放在这里,它就是这样愚蠢的东西。我在想更复杂的事情。。。谢谢你的帮助!必须使用.on方法,因为我在内容上使用了.load()。在.load()之后,除非我使用.on,否则任何按钮都不会工作。谢谢你的回复!如果您不使用匿名内部函数,而是将它们分配给一个var,然后在加载代码后通过单击将它们附加,这也会起作用。也就是说,have
var toggle=function(elm){$(elm).toggle();}
并在.load()do
$('#id')中单击(toggle)
// Show the stats slide out
$('#buildscore').click(function(){     
    $(".buildscore").slideToggle();
});
// Hide / show the comments
$('#hideshow').click(function(){      
    $('.commentsbox').toggle();
});