这个
input[type="number"]
有
max
属性,因此用户不能单击高于给定值的值。但这不包括键入的数字,它们可能远远超过给定的最大值。因此,使用jQuery,我想为这个问题提供一个解决方案。我已经得到了这个:
var productPageInput = $('#product-options-wrapper .option input[type="number"].qty');
var max = 60;
productPageInput.attr('max', max);
productPageInput.bind('keyup input', function(e){
console.log($(this).val());
if( $(this).val() > max ){
$(this).val() = max;
}
});
但是,每次我执行这段代码,输入60以上,就会出现控制台错误:
Uncaught ReferenceError: Invalid left-hand side in assignment(â¦)
它指向这条线:
$(this).val() = max;
这里怎么了?