简体   繁体   English

鼠标悬停时打开DropDownList

[英]Open DropDownList when mouse over

I have a DropDownList in a updatepanel and bind it in code behind. 我在updatepanel中有一个DropDownList,并将其绑定在后面的代码中。

 <span id="dropdown" class='css-select-moz groupTitle' style="margin-right: 880px; padding-top: 0; margin-top: 0px; background: transparent">
                                <asp:DropDownList ID="SubCategoryDropDownList" AutoPostBack="true" OnSelectedIndexChanged="SubCategoryDropDownList_SelectedIndexChanged" runat="server" CssClass="css-select"></asp:DropDownList>
                            </span>

and style 和风格

 .css-select {
-moz-appearance: window;
background-position: left bottom;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
padding: 2px;
border: none;
-moz-appearance: none;
text-indent: 0.01px;
text-overflow: ellipsis;
background: transparent;
color: #FF8000;
}

I want open DropDown when mouse over, I use this script 我想在鼠标悬停时打开DropDown,我使用此脚本

$(document).ready(function(){
$("#SubCategoryDropDownList").hover(function(){
$(this).trigger('click');
 });
})

But don't open items, How to open DropDownList when mouse over? 但是不要打开项目,鼠标悬停时如何打开DropDownList?

See you used .trigger() and you have to specify the click in the code to trigger, since it is not there the trigger won't be executed. 看到您使用了.trigger()并且必须在代码中指定要触发的单击,因为它不存在,因此不会执行触发。

Note: 注意:

Execute all handlers and behaviors attached to the matched elements for the given event type. 执行给定事件类型的所有处理程序和附加到匹配元素的行为。

What it means is this: 这是什么意思:

$("#foo").on( "click", function() { //<--the given event type "click"
   alert('clicked');
});
$("#foo").trigger("click"); // <---triggering the same event type "click"

From the documentation: 从文档中:

Any event handlers attached with .on() or one of its shortcut methods are triggered when the corresponding event occurs. 发生相应事件时,将触发附加有.on()或其快捷方式之一的任何事件处理程序。 They can be fired manually, however, with the .trigger() method. 但是,可以使用.trigger()方法手动将其触发。 A call to .trigger() executes the handlers in the same order they would be if the event were triggered naturally by the user: 调用.trigger()会以与事件由用户自然触发的顺序相同的顺序执行处理程序:

What Hiral answered should do the trick BUT have in mind that it is a completely client handled functionality and you should either remove the AutoPostback="True" or utilize some sort of AJAX in order to do this. Hiral回答的应该做的是技巧,但要记住,它是完全由客户端处理的功能,您应该删除AutoPostback="True"或使用某种AJAX来做到这一点。 When the option's click event is triggered a PostBack occurs. 触发选项的单击事件时,将发生发。 Now the catch is that the option box in the response is still closed, so you don't notice the effect of the client script. 现在要注意的是,响应中的选项框仍处于关闭状态,因此您不会注意到客户端脚本的效果。

请参阅此Fiddel ,它将帮助您了解: http://jsfiddle.net/AndreasPizsa/NzvKC/ : http://jsfiddle.net/AndreasPizsa/NzvKC/ :-)

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

相关问题 Description鼠标悬停在说明上时保持打开状态的框 - DescriptionBox that stays open when mouse is over description 如何在鼠标悬停时打开素面selectOneMenu - How to open primefaces selectOneMenu on mouse over 将鼠标悬停在列表上时,传单打开弹出窗口 - Leaflet open popup on mouse hover over list 为什么鼠标悬停时我的悬停按钮下拉菜单没有保持打开状态? - Why does my hover button dropdown not stay open when I mouse-over? 如何在鼠标移动到特定内容区域时打开丰富的工具提示? - How to open a rich:tooltip when mouse is moving over specific area of content? 我希望子菜单在鼠标移到上方时保持打开状态 - I want the sub-menu to remain open when the mouse moves over it 当鼠标移过(或离开)面板时,如何使列/手风琴打开(或折叠)? - How to make columns/accordion open (or collapse) when the mouse moves over (or leaves) the panel? 鼠标悬停时隐藏并设置动画 - hide and animate when mouse over 鼠标结束时,单词会突出显示 - Words highlight when mouse is over 在鼠标悬停时打开div并保持打开状态直到鼠标移出? - Opening a div on mouse over and staying open until mouse is moved out?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM