jQuery绑定错误“事件未定义”

时间:2022-06-01 18:59:25

Currently I'm doing something like this in markup

目前我在标记中做了类似的事情

<input type="text" ONKEYPRESS="InputNumeric(event);" id="txtNumber" />

But I want to use the jQuery bind method instead for all the obvious reasons.

但我想使用jQuery绑定方法代替所有明显的原因。

jQuery(function($)
{
    $("#txtNumber").bind("keyup", InputNumeric(event));
});

But when I try the above I get the below error

但是当我尝试以上操作时,我得到以下错误

"event is not defined"

“事件未定义”

What should this syntax look like?

这个语法应该是什么样的?

EDIT

The actual solution I got working is shown below.

我开始工作的实际解决方案如下所示。

$("#txtPriority").keypress(function (e) { InputInteger(e); });

3 个解决方案

#1


4  

jQuery(function($)
{
    $("#txtNumber").bind("keyup", function(event) {InputNumeric(event);});
});

#2


3  

looks like InputNumeric is an existing function that takes an event as parameter, In that case this should also work

看起来像InputNumeric是一个将事件作为参数的现有函数,在这种情况下,这也应该有效

$("#txtNumber").bind("keyup",InputNumeric);

#3


2  

Arguments passed back via jquery callbacks are always implied, so simply writing the function name is enough.

通过jquery回调传回的参数总是隐含的,所以简单地编写函数名就足够了。

$("#txtNumber").bind("keyup",InputNumeric);

function InputNumeric(event){
    $(event.target).dosomething(); // is the same as
    $(this).dosomething();
}

Example: http://www.sanchothefat.com/dev/sfhelp/jquery-args.html

#1


4  

jQuery(function($)
{
    $("#txtNumber").bind("keyup", function(event) {InputNumeric(event);});
});

#2


3  

looks like InputNumeric is an existing function that takes an event as parameter, In that case this should also work

看起来像InputNumeric是一个将事件作为参数的现有函数,在这种情况下,这也应该有效

$("#txtNumber").bind("keyup",InputNumeric);

#3


2  

Arguments passed back via jquery callbacks are always implied, so simply writing the function name is enough.

通过jquery回调传回的参数总是隐含的,所以简单地编写函数名就足够了。

$("#txtNumber").bind("keyup",InputNumeric);

function InputNumeric(event){
    $(event.target).dosomething(); // is the same as
    $(this).dosomething();
}

Example: http://www.sanchothefat.com/dev/sfhelp/jquery-args.html