jQuery'if .change()或.keyup()' [英] jQuery 'if .change() or .keyup()'

查看:139
本文介绍了jQuery'if .change()或.keyup()'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery时,我希望在 .change() .keyup()是运行一个函数

类似于此。

  if(jQuery(' :input')。change()|| jQuery(':input')。keyup())
{
alert('something happened!');
}

编辑

抱歉,我忘了提及。 .change() .keyup()都需要一些变量在范围内。

解决方案

您可以通过用空格分隔多个事件来绑定多个事件:

<$ p






$ b $ code>

docs here

希望有所帮助。欢呼!


Using jQuery i would like to run a function when either .change() or .keyup() are raised.

Something like this.

if ( jQuery(':input').change() || jQuery(':input').keyup() )
{
    alert( 'something happened!' );
}

EDIT

Sorry i forgot to mention. Both .change() and .keyup() need some of the variables to be in-scope.

解决方案

you can bind to multiple events by separating them with a space:

$(":input").bind("keyup change", function(e) {
    // do stuff!
})

docs here.

hope that helps. cheers!

这篇关于jQuery'if .change()或.keyup()'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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