如何强制输入框不能为空,例如:如果用户清除它,则始终显示“0”
(function ($) {
$(document).ready(function () {
$('#value1').keyup(function () {
/* something that it has at least '0' as content */
});
});
}(jQuery));
答案 0 :(得分:4)
它需要比这更复杂吗?
$('#value1').keyup(function() {
if($(this).val() == '')
$(this).val(0);
});
答案 1 :(得分:0)
(function ($) {
$(document).ready(function () {
$('#value1').keyup(function () {
if ($('#value1').val() == '') {
$('#value1').val(0);
}
});
});
}(jQuery));