<div class="htmlarea"> <textarea id="runcode28907"> <title>JS Day by Day 001 - 행과 셀의 사용</title> <form action="" method="post" name="loginFrm"> <table> <tbody id="validBody"> <tr> <td align="right">用户名 <font color="red">*</font> :</td> <td><input type="text" name="username"></td> </tr> <tr> <td align="right">密码 <font color="red">*</font> :</td> <td><input type="password" name="username"></td> </tr> <tr> <td align="right">子系统 <font color="red">*</font> :</td> <td> <select name="systemname"> <option value="">---请选择---</option> <option value="HR">人力资源系统</option> <option value="PUR">采购系统</option> <option value="SAL">销售系统</option> </select> </td> </tr> </tbody> <tbody> <tr> <td colspan="2"> <input type="button" value="提交" name="submit" onclick="validForm(this.form, 'validBody')"> <input type="reset" value="Reset" name="reset"> </td> </tr> </tbody> </table> </form> </textarea> <br><input onclick="runEx('runcode28907')" type="button" value="运行代码"><input onclick="doCopy('runcode28907')" type="button" value="复制代码"> <input onclick="doSave(runcode28907)" type="button" value="保存代码"> <a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">[Ctrl A 모두 선택 참고: </a>외부 J를 도입해야 하는 경우 실행하려면 새로 고쳐야 합니다 </div>]<script type="text/javascript"> function validForm(curForm, bodyName){ var bodyObj = document.getElementById(bodyName); var rowObj = null; var cellObj = null; if (bodyObj == null){ return false; } // 引用rows for (var i = 0; i < bodyObj.rows.length; i ++){ rowObj = bodyObj.rows[i]; // 带*的必须输入,引用cells if (rowObj.cells[0].innerText.indexOf("*") > 0){ if (rowObj.cells[1].childNodes[0].value == ""){ alert(rowObj.cells[0].innerText.replace(" * :", "") + "不能为空!"); return false; } } } alert("Pass validation"); //curForm.submit(); } </script>