触发点击悬停时的选择框 [英] Trigger click on select box on hover

查看:99
本文介绍了触发点击悬停时的选择框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个选择框自动弹出打开,当使用鼠标悬停在它,就像他们点击它。这是可能的吗?

I'm trying to have a select box automatically pop open when the use hovers over it, as if they had clicked it. Is this possible?

我想我可以很容易地用jQuery ...

I would think I could do this easily with jQuery...

$("#settings-select").mouseover(
    function(){
        $(this).trigger("click");
    }
);

但这没什么。任何想法?

But that does nothing. Any ideas?

推荐答案

我终于得到这个工作!您必须选择;正如其他人已经指出的,您不能使用正常的 select 来执行此操作,因为没有可用的事件。但是当鼠标移动到 select 时,这将弹出打开菜单,并在mouseout时关闭它,这是我想要的确切效果。

I finally got this to work! You need Chosen; as others have pointed out, you can't do this with a normal select because there are no events available to use. But this will pop open the menu when you mouseover the select and close it when you mouseout, which is the exact effect I wanted.

HTML:

<select id="dropdown" data-placeholder="Choose&hellip;">
    <option value="one">Option 1</option>
    <option value="two">Option 2</option>
    <option value="three">Option 3</option>
</select>

JS:

$("#dropdown").chosen().next(".chzn-container").hover(
    function(){
        $("#dropdown").trigger("liszt:open");
    },
    function(){
        $(this).trigger("click");
    }
);

$(#dropdown)。trigger(liszt:open ); 是打开菜单。没有等价的 liszt:close 事件触发时,你想关闭它(据我所知),但触发点击它具有相同的效果。

$("#dropdown").trigger("liszt:open"); is what opens the menu. There is no equivalent liszt:close event to trigger when you want to close it (as far as I know), but triggering a click on it instead has the same effect.

这篇关于触发点击悬停时的选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆