我目前正在使用 jQuery 检查 value 是否为 Nan,并且希望将检查扩展到不为 null 或为空,但不确定如何执行此操作,这是我的代码;
<script type="text/javascript"> // ensure quantity textbox is numeric
$(document).ready(function () {
$('[id$=txtQuantity]').change(function () {
if(isNaN(this.value)) {
alert("Please ensure the quantity specified is numeric");
$(this).val("1");
}
else{
$(this).val(this.value);
}
});
});
Run Code Online (Sandbox Code Playgroud)