JS实现失去焦点判断input内容是否大于0

静态页面:

<input name="marketPrice" id="marketPrice" onblur="valid()" value="${goods.marketPrice}" >

JS代码:

<script type="text/javascript">


function valid(){
 var marketPrice = document.getElementById("marketPrice");

 if(marketPrice.value<0){
    alert("市场价格不能为负数!");
    marketPrice.value="";//清空输入
    marketPrice.focus();//获得焦点
     }

</script>

猜你喜欢

转载自blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/82417174