代码之家  ›  专栏  ›  技术社区  ›  Toran Billups

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

  •  0
  • Toran Billups  · 技术社区  · 16 年前

    目前,我正在标记中做这样的事情

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

    但出于所有显而易见的原因,我想使用jQuery绑定方法。

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

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

    “事件未定义”

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

    编辑

    我得到的实际解决方案如下所示。

    $("#txtPriority").keypress(function (e) { InputInteger(e); });
    
    3 回复  |  直到 16 年前
        1
  •  4
  •   matthewk    16 年前
    jQuery(function($)
    {
        $("#txtNumber").bind("keyup", function(event) {InputNumeric(event);});
    });
    
        2
  •  3
  •   kamal.gs    16 年前

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

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

        3
  •  2
  •   roborourke    16 年前

    通过jquery回调传递回来的参数总是隐含的,因此只需写函数名就足够了。

    $("#txtNumber").bind("keyup",InputNumeric);
    
    function InputNumeric(event){
        $(event.target).dosomething(); // is the same as
        $(this).dosomething();
    }
    

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