[英]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()
并且必须在代码中指定要触发的单击,因为它不存在,因此不会执行触发。
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"
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.