我有这段代码,它正在从文本框中读取值,我认为在尝试 parseInt() 之前检查 '' 是安全的,但显然不是。
我收到错误:
Uncaught TypeError: Cannot call method 'toLowerCase' of undefined
使用此代码:
var total = 0;
$.each('.reg-input', function () {
if ($(this).val() == '') {
}
else {
total += parseInt($(this).val()); //this line throwing error
}
});
if (total == 0) {
$('.RegisterContainer').hide();
}
最佳答案
'.reg-input'
是一个字符串,在这种情况下 this
也将是一个字符串,而不是 dom 元素。试试这个:
$('.reg-input').each(function(){...
关于javascript - 无法调用未定义的方法 'toLowerCase',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12609059/