with 语句可以方便地用来引用某个特定对象中已有的属性,但是不能用来给对象添加属性。要给对象创建新的属性, 必须明确地引用该对象
<html> <head> <script type="text/javascript"> function validate_email(field,alerttxt){ with (field){ apos=value.indexOf("@") dotpos=value.lastIndexOf(".") if (apos<1||dotpos-apos<2) { alert(alerttxt);return false }else { return true } } } function validate_form(thisform){ with (thisform){ if (validate_email(email,"Not a valid e-mail address!")==false){ email.focus(); return false } } } </script> </head> <body> <form action="submitpage.htm"onsubmit="return validate_form(thisd);" method="post"> Email: <input type="text" name="email" size="30"> <input type="submit" value="Submit"> </form> </body> </html>
本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1902348
原文地址:http://suyanzhu.blog.51cto.com/8050189/1902348