日期:2014-05-16 浏览次数:20448 次
function TiJiao(form_name,title_name,show_error) { //在这里你需要找到form_name的对象 var form = document.getElementsByName(form_name)[0]; if (Trim(form.title_name.value)=='') { alert(show_error); form_name.title_name.focus(); return false; } }
------解决方案--------------------
<script> function Trim(str){ var rtnStr; rtnStr="" for (var i=0;i<str.length;i++){ if (str.charAt(i)!=" "){ rtnStr=str.substr(i); break; } } return rtnStr; } function TiJiao(form1,i,show_error) { if (Trim(form1.elements[i].value)=='') { alert(show_error); form1.elements[i].focus(); return false; } } function check(tt1) { tt=document.getElementById(tt1); TiJiao(tt,0,'请输入名称'); TiJiao(tt,1,"请输入密码"); } </script> <FORM name="form1" method="post" action="" id="form1" onSubmit="return check('form1')"> <input type="text" name="acc' id="acc" /> <input type="text" name="psd' id="psd" /> <input type="submit" name="btsub' id="btsub" value="submit"/> </FORM>