0
点赞
收藏
分享

微信扫一扫

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>

 

举报

相关推荐

0 条评论