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