且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery无法读取未定义的属性"toLowerCase"

更新时间:2023-02-22 16:16:48

ajaxValidation($(this))中的this位不是您认为的:

The this bit in ajaxValidation($(this)) isn't what you think it is: it's actually window, since it's being called by setTimeout().

一种解决方案是将$(this)分配给函数 之外的变量,如下所示:

One solution is to assign $(this) to a variable outside the function, like so:

$('.required').keyup(function() {
    clearTimeout(timerId);
    var $this = $(this);

    timerId = setTimeout(function() {
        ajaxValidation($this);
    }, 200);
});