Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在完成后禁用另一个事件单击事件_Javascript_Jquery - Fatal编程技术网

Javascript 如何在完成后禁用另一个事件单击事件

Javascript 如何在完成后禁用另一个事件单击事件,javascript,jquery,Javascript,Jquery,我有4个li元素,我想当鼠标悬停(mouseenter,mouseleave)时,他们中的每个人都会为选择的每个人更改背景色 我使用以下代码执行此工作: <script> $( document ).ready(function() { $('#center-group').children().on('mouseenter',function(){ $(this).children('

我有4个
li
元素,我想当鼠标悬停(
mouseenter
mouseleave
)时,他们中的每个人都会为选择的每个人更改背景色

我使用以下代码执行此工作:

<script>
        $( document ).ready(function() 
        {
            $('#center-group').children().on('mouseenter',function(){
                    $(this).children('.topmenu').children('.r-part').css('background-color','#810000');
                    $(this).children('.topmenu').children('.r-part').children('.r-part-bot').css('background-color','#980000');
            });
            $('#center-group').children().on('mouseleave',function(){
                    $(this).children('.topmenu').children('.r-part').css('background-color','#404040');
                    $(this).children('.topmenu').children('.r-part').children('.r-part-bot').css('background-color','#4c4c4c');
            });
        });
        </script>

$(文档).ready(函数()
{
$(“#中心组”).children().on('mouseenter',function()){
$(this).children('.topmenu').children('.r-part').css('background-color','#810000');
$(this).children('.topmenu').children('.r-part').children('.r-part-bot').css('background-color','#980000');
});
$(“#中心组”).children().on('mouseleave',function(){
$(this).children('.topmenu').children('.r-part').css('background-color','404040');
$(this).children('.topmenu').children('.r-part').children('.r-part-bot').css('background-color','#4c');
});
});
现在我想当我选择(
点击事件
)时,每个人都会改变背景颜色,不要在顶部活动!!!怎么做???请引导我……

正确的代码:

$(document).on('mouseenter','#center-group li',function(){
                    $(this).children('.topmenu').children('.r-part').css('background-color','#810000').children('.r-part-bot').css('background-color','#980000');;
            });
            $(document).on('mouseleave','#center-group li',function(){
                    $('#center-group').children().not('.selected').children('.topmenu').children('.r-part').css('background-color','#404040').children('.r-part-bot').css('background-color','#4c4c4c');
            });

            $(document).on('click','#center-group li',function(){
                $(this).toggleClass('selected');
                $(this).siblings().removeClass('selected');
                $('#center-group').children('.selected').children('.topmenu').children('.r-part').css('background-color','#810000').children('.r-part-bot').css('background-color','#980000');
                $('#center-group').children().not('.selected').children('.topmenu').children('.r-part').css('background-color','#404040').children('.r-part-bot').css('background-color','#4c4c4c');

为什么要将两个事件绑定到同一对象?
$('\center group').children()。在('mouseenter',function(){/code>上,这应该是
$('\center group').children()。on('mouseleave',function(){
关于第二个问题。很抱歉,我键入了这个错误并对其进行了编辑。现在回答我。您可以复制粘贴html吗?您可以做的一件事是停止事件传播,并使用jquery.off()函数()关闭事件