Trigger Change event and keyup event in select element

元气小坏坏 提交于 2019-12-05 22:51:09

问题


I have some codes that should be run when a select element changes.I do it with jquery in this way:

$("#myselect").change(function() {
    .......
});

But I want these codes run also when user change the select using keyword arrows. As i found the event for this purpose is 'keyup' . So will be :

$("#myselect").keyup(function() {
   .......
});

How can i combine these two event?


回答1:


You can use .bind() to combine them:

$("#myselect").bind("change keyup", function(event){
   //Code here
});

See reference here.




回答2:


You can write the function that you want to call separately, and then assign it to the events you want to handle, sth like:

var func = function(){};

$("#myselect").change(func()).keyup(func());


来源:https://stackoverflow.com/questions/7316283/trigger-change-event-and-keyup-event-in-select-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!