JS验证表单是否有空项

<form action="{:url('index/addnews')}" method="post" name="news" onSubmit="return myCheck()">
	<script type="text/javascript">
	  	function myCheck(){
	    	for(var i=0;i<document.news.elements.length-1;i++)
	    	{
	     		if(document.news.elements[i].value=="")
	     		{
	     			alert("当前表单不能有空项!");
	       			document.news.elements[i].focus();
	       			return false;
	    		}
	    	}
		        alert("提交成功!");
		        return true;					        
	  	}
	</script>
</form>

猜你喜欢

转载自blog.csdn.net/qq_39383675/article/details/83024710