在选择元素中触发Change事件和keyup事件 [英] Trigger Change event and keyup event in select element

查看:255
本文介绍了在选择元素中触发Change事件和keyup事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当select元素改变时,我有一些代码应该运行.我用jquery来做到这一点:

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

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

但是我希望这些代码在用户使用关键字箭头更改选择时也能运行.当我发现用于此目的的事件是'keyup'.将会是:

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?

推荐答案

您可以使用.bind()对其进行组合:

You can use .bind() to combine them:

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

请参阅此处的参考.

这篇关于在选择元素中触发Change事件和keyup事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆