简体   繁体   English

按钮元素内div元素上的jQuery hover()事件

[英]jQuery hover() event on div element within a button element

I can't seem to get jQuery to notice the div within the following markup 我似乎无法让jQuery注意到以下标记中的div

<button class="button submit positive right" id="omnisubmit" type="submit">
    <div class="label">Submit</div> 
    <div class="controller">&nbsp;</div>
</button>

And here is the jQuery I'm currently using: 这是我当前正在使用的jQuery:

$("button#omnisubmit div.controller").hover(function () {
            console.log("Hover...");
        });

However, jQuery doesn't seem to pick up when the mouse is hovering over that div, $("button#omnisubmit div.controller").hover(... works correctly, of course. 但是,当鼠标悬停在该div上时,jQuery似乎没有启动, $("button#omnisubmit div.controller").hover(...当然可以正常工作。

I have a feeling it's because putting divs inside buttons may not be standard HTML? 我感觉是因为将div放在按钮内可能不是标准的HTML?

Sounds like what you really should do is have two button elements that are styled to look like one. 听起来您真正应该做的是拥有两个按钮元素,它们的样式看起来像一个。

Something like the jQuery UI Button element split button example. 类似于jQuery UI Button元素拆分按钮示例。

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

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