冲突的jQuery脚本,两个不同的切换功能相互影响

时间:2014-02-13 19:09:01

标签: 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();
    $('.commentsboxhidden').toggle();
});

评论切换工作正常,构建评分也是如此。但是buildscore统计数据滑出功能也会切换注释框div。

查看小提琴:

http://jsfiddle.net/FsUDj/

提前致谢。

1 个答案:

答案 0 :(得分:0)

保持简单。简单的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>

简单的JQuery,没有不必要的位:

// Show the stats slide out
$('#buildscore').click(function(){     
    $(".buildscore").slideToggle();
});
// Hide / show the comments
$('#hideshow').click(function(){      
    $('.commentsbox').toggle();
});
相关问题