如何通过“onmouseover”删除选择列表?

发布于 2024-10-31 15:29:25 字数 205 浏览 4 评论 0原文

如何使用 onmouseover 下拉选择列表而不是单击它。 无法在 JavaScript 中单击选择列表来模拟它。 例如: onmouseover="(this.click())"

另外,在 javascript 中设置“选择列表的大小”=“其长度”并不能准确模拟单击事件,因为相邻布局发生了变化。 我尝试使用 z-index 和位置属性,但没有帮助。

How can I drop down a select list with onmouseover instead of clicking it.
Select list cannot be clicked in javascript to emulate that.
eg: onmouseover="(this.click())"

Also setting the 'size of select list' = 'its length' in javascript does not accurately emulate the click event because the adjacent layout changes.
I tried using z-index and position attribute but doesn't help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

琴流音 2024-11-07 15:29:25

的巧妙技巧

这是来自旧的 devshed 帖子选择框 展开 onMouseOver - Dev Shed

这是一个实际示例:

http://jsfiddle.net/87nyG/1< /a>


就我个人而言,我更喜欢第 3 方或自定义解决方案,而不是破解

Here's a clever hack from an oldish devshed post

Select box expand onMouseOver - Dev Shed

here's an example in action:

http://jsfiddle.net/87nyG/1


Personally I'd prefer a 3rd party or custom solution as opposed to hacking the <select> element

盛夏已如深秋| 2024-11-07 15:29:25

它可能会有所帮助:https://developer.mozilla.org/en/DOM/event。 initMouseEvent

编辑。不,事实并非如此:(

It might help: https://developer.mozilla.org/en/DOM/event.initMouseEvent

edit. Nah, it doesn't :(

千仐 2024-11-07 15:29:25

使用本机 HTML Select 无法完成您所要求的操作。您必须寻找第三方选项。

看看这里的可能性:http://jquery.sanchezsalvador.com/page/jquerycombobox。 ASPX

It isn't possible to do what you're asking using a native HTML Select. You'll have to search out third party options.

Take a look at here for a possibility: http://jquery.sanchezsalvador.com/page/jquerycombobox.aspx

-残月青衣踏尘吟 2024-11-07 15:29:25

刚刚遇到这个问题。我知道这个问题已经得到解答,但如果有人来这里寻找更优雅的解决方案,您可以使用 jquery 来实现:

$("#select_id").hover(
    function(){
        $(this).attr('size',13); //My select had months, so 13 was appropriate. obviously you can change this
        $(this).css('position','absolute'); //prevents sibling elements from being pushed down
    },
    function(){
        $(this).attr('size',0); //resets select on mouseout
    }
);

这将防止“黑客”HTML 中的 select 标记。

Just ran into this problem. I know it was answered already, but if anyone comes here looking for a more elegant solution, you can do this with jquery:

$("#select_id").hover(
    function(){
        $(this).attr('size',13); //My select had months, so 13 was appropriate. obviously you can change this
        $(this).css('position','absolute'); //prevents sibling elements from being pushed down
    },
    function(){
        $(this).attr('size',0); //resets select on mouseout
    }
);

This will prevent 'hacking' the select tag in the HTML.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文