纯js 判断表单为空 阻止 input 提交

<!DOCTYPE html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>untitled</title>
<script type="text/javascript">
function testContent(obj){
    if(document.getElementById(obj).value.length==0){
        alert('不能为空');return false;
        }
    }
</script>
</head> 
<body> 
<form name="search" method="post" action="">
<input name="input" id="test">
<input type="button" name="go" value="goSearch" onClick=" return testContent('test')">
</form>
</body> 
</html>

 

posted @ 2016-04-05 20:02  WilliamShaw  阅读(1943)  评论(0)    收藏  举报