简体   繁体   English

jQuery-触发div上的mouseenter的单击,如果单击任何其他按钮,则取消单击

[英]Jquery - Triggering click on mouseenter on div and unclick if clicked on any other button

I want to trigger a click on "bigbutton" when hovering over a div, "div1". 将鼠标悬停在div“ div1”上时,我想触发对“ bigbutton”的点击。 And if I click on any other button, the "bigbutton" needs to be unclicked and the click need to move the newly clicked button. 如果我单击任何其他按钮,则需要取消单击“大按钮”,并且单击需要移动新单击的按钮。 Here's what I've tried: 这是我尝试过的:

Html HTML

<div class="div1">
<button id="bigbutton">bigbutton</button>
<button type="button" id="button1">button1</button>
<buttton type="button" id="button2">button2</button>
</div>

Jquery jQuery的

 $(document).ready(function () {
    $("#bigbutton").click(function () {
        $(this).css("background-color", "red");
    });
    $(".div1").mouseenter(function () {
        $("#bigbutton").trigger('click');
    });
});

With the above code, I'm only able to do half of what I want. 使用上面的代码,我只能完成我想要的一半。 So, tried the following, did not work. 因此,尝试以下方法,没有用。

$(document).ready(function () {
    $("#bigbutton").click(function () {
        $(this).css("background-color", "red");
    });
    $(".div1").mouseenter(function () {
        $("#bigbutton").on('click');
    });
    $("button").click(function () {
        $("#bigbutton").off('click');
    });
});

PS. PS。 I'm extremely sorry about the formating errors as my phone has a broken screen. 由于手机屏幕坏了,我为格式化错误感到非常抱歉。

Something like this? 像这样吗

  $(document).ready(function () { $("#bigbutton").click(function () { $(this).css("background-color", "red"); }); $(".div1").mouseover(function () { $("#bigbutton").trigger('click'); }); $("#button1").click(function () { $("#bigbutton").off('mouseover').css("background-color", ""); }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="div1"> <button id="bigbutton">bigbutton</button> <button type="button" id="button1">button1</button> <buttton type="button" id="button2">button2</button> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM