JS前台页面验证文本框非空

效果图:

代码:

源代码:

<script type="text/javascript">

function check(){

   var xm = document.getElementById("xm").value;

   if(xm ==  null || xm == ''){

        alert("用户名不能为空");

        return false;

   }

   return true;

}

</script>

</head>

<body>

<form action="${pageContext.request.contextPath }/insertStuServlet" method="get" onsubmit="return check()">

姓名<input name="xm" id="xm" type="text" /><br />

性别<input name="xb" type="radio" value="男" />男&nbsp;&nbsp;&nbsp;&nbsp; 

<input name="xb" type="radio" value="女" />女<br /> 

出生日期<input name="csrq" type="text" class="Wdate" onClick="WdatePicker()" /><br /> 

分数<input name="fs"type="text" /><br /> 

<input name="" type="submit" value="提交" />

</form>

猜你喜欢

转载自www.cnblogs.com/zbguolei/p/9945366.html
今日推荐