[英]Uncaught TypeError: Object .NumCon has no method 'apply'
I want run a jquery code that if number value text input was under of 7
, the result is false. 我想运行一个jquery代码,如果数值文本输入低于7
,则结果为false。 but i get following error: 但我得到以下错误:
Uncaught TypeError: Object .NumCon has no method 'apply'
f.event.dispatch
f.event.add.h.handle.i
What do i do? 我该怎么办?
Demo: http://jsfiddle.net/FZMsP/ 演示: http : //jsfiddle.net/FZMsP/
This is my code: 这是我的代码:
<form>
<input type="password" name="user_pass" class="NumCon" id="7">
</form>
function NumCon() {
var result = true;
$(this).closest("form").find('.NumCon').each(function () {
var size = this.value.length;
var NumVal = $(this).attr('id');
if (size <= NumVal) {
$(this).css("background", "#ffc4c4");
result = false;
}else{
$(this).css("background-color", "#ffffec");
}
});
}
$('.NumCon').live('keyup', NumCon());
You're calling your function from inside of the definition line, which is (for some reason) then interpreted as an object. 你是从定义行内部调用你的函数,这是(出于某种原因)然后被解释为一个对象。
$('.NumCon').on('keyup', NumCon);
Solves your problem. 解决你的问题。
.live has now been depreciated, seems youre now meant to use: $(document).on("click", "a.offsite", function(){ alert("Goodbye!"); }); .live现在已被折旧,现在看来你现在打算使用:$(document).on(“click”,“a.offsite”,function(){alert(“Goodbye!”);});
The solution is 解决方案是
$('.NumCon').on('keyup', yourFunction(yourParameters));
source http://api.jquery.com/on/ 来源http://api.jquery.com/on/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.