jsp中非空判断
function中uname要和id的值相匹配,但是这样不专业,要显示我的专业性,我将使用document获得name的值来判断是否为空,应为这样是专业的写法,我要时刻记住我是专业的
<script type="text/javascript" src="js/jQuery1.11.1.js"></script></head> <script type="text/javascript"> function mu(){ if(uname.value.length==0){ alert("不能为空"); return false; }
}
function mu(){ var uname = document.all("name"); if(uname.value.length==0){ alert("不能为空"); return false; } }
</script> <body> <form id="form" method="post" action="AttencesServlet?XG=xg" onsubmit="return mu()" > <table align="center" > <tr> <td>员工姓名</td> <td>所属部门</td> <td>考勤日期</td> <td>考勤状态</td> </tr> <c:forEach items="${nameList}" var="item"> <tr> <td><input id="uname" type="text" value="${item.empName }" name="name" /></td> <td><input type="text" value="${item.dept } " name="dept" /></td> <td><input type="text" value="${item.chkDate }" name="dates" /></td> <td> <select name="status" > <c:if test="${item.status eq '未考勤' }"> <option value="未考勤" selected="selected">未考勤</option> <option value="已考勤">已考勤</option> </c:if> <c:if test="${item.status eq '已考勤' }"> <option value="未考勤">未考勤</option> <option value="已考勤" selected="selected">已考勤</option> </c:if> </select> <!-- <option value="未考勤">未考勤</option> <option value="已考勤">已考勤</option> --> </td> <td><input type="submit" /></td> <td><input type="hidden" value="${item.id}" name="id" /></td> </tr> </c:forEach> </table> </form> </body>