更新时间: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);
});