gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 09:03:01 24 4
gpt4 key购买 nike

我有 4 个 li 元素,我希望当悬停时(mouseentermouseleave),每个元素都会为选择的每个元素更改背景颜色.

我用这段代码完成了这个工作:

<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>

现在我想当选择(点击事件)时,li中的每个人都改变背景颜色并且不工作顶部事件!怎么办呢???请指导我......

最佳答案

这个正确的代码:

$(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');

关于javascript - 如何在完成单击事件后禁用另一个事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17462987/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com