Javascript Jquery 多选事件处理程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5492042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 17:25:51  来源:igfitidea点击:

Jquery multiselect event handler

javascriptjqueryhtml

提问by john

I have an html dropdown. I want to fire an event whenever the selection changes in any way. I tried registering a 'click' event but this didnt work when multi-selecting (either by dragging the mouse or holding down shift + down arrow).

我有一个 html 下拉菜单。I want to fire an event whenever the selection changes in any way. 我尝试注册一个“点击”事件,但这在多选(通过拖动鼠标或按住 shift + 向下箭头)时不起作用。

So basically, how can I fire an event on anyselection change?

所以基本上,如何在任何选择更改时触发事件?

回答by Rocket Hazmat

Try using the onchangeevent.

尝试使用该onchange事件。

$('#mySelect').change(function(){
    alert($(this).val());
});

回答by thesunneversets

Would .change() do the trick?

.change() 能解决问题吗?

http://api.jquery.com/change/

http://api.jquery.com/change/

Certainly there seems to be a working demo of a multi-select box on that page...

当然,该页面上似乎有一个多选框的工作演示......

回答by John Hoven

jquery 1.4: $("#mySelector").change(myChangeEvent);before: $("#mySelector").bind("change", myChangeEvent);

jquery 1.4: $("#mySelector").change(myChangeEvent);之前: $("#mySelector").bind("change", myChangeEvent);

function myChangeEvent(e){

}