开发者

Trigger Change event and keyup event in select element

开发者 https://www.devze.com 2023-04-02 11:34 出处:网络
I have some codes that should be run when a select element changes.I do it with jquery in this way: $(\"#m开发者_如何学编程yselect\").change(function() {

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

$("#m开发者_如何学编程yselect").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?


You can use .bind() to combine them:

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

See reference here.


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());
0

精彩评论

暂无评论...
验证码 换一张
取 消