麻烦专家来个解释,关于这句if(s.charAt(i)!="")
程序代码:
<html> <head><title></title> <script language="javascript"> function checkValid(s) { var len=s.length; for(var i=0;i<len;i++) { if(s.charAt(i)!="")/*什么意思这句,为什么要这句,我把它删除直接return false;也行啊?*/ { return false; } } return true; } function okHandle() { if(checkValid(document.test.userName.value)) { alert("用户名空了"); } else if(checkValid(document.test.passWord.value)) { alert("密码空了"); } else { alert("okok!!"); } } function cancelHandle() { document.test.userName.value=""; document.test.passWord.value=""; } </script> </head> <body> <form name="test"> <font size=2">用户名:</font> <input type="text" name="userName"/> <br/><br/> <font size=2">用户密码:</font> <input type="text" name="passWord"/> <br/><br/> <input type="button" name="ok" value="确定" onclick="okHandle()"/> <input type="button" name="cancle" value="取消" onclick="cancelHandle()"/> </form> </body> </html>