javascript中with(thisform)是什么意思
javascript中with(thisform)是什么意思?
<html>
<head>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false}
else {return true}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false}
}
}
</script>
</head>
<body>
<form action="submitpage.htm" onsubmit="return validate_form(this)" method="post">
Email: <input type="text" name="email" size="30">
<input type="submit" value="Submit">
</form>
</body>
</html>
------解决方案--------------------http://www.w3school.com.cn/js/pro_js_statements_with.asp
这里是with的用法
--------------------------------------帅签分割线-------------------------------------------------
------解决方案--------------------function validate_form(thisform)
{
if (validate_required(thisform.email,"Email must be filled out!")==false)
{thisform.email.focus();return false}
}
--------------------------------------帅签分割线-------------------------------------------------
------解决方案--------------------thisform.email
你本来要这么写引用email
加了with就不用了
直接 email就可以了
------解决方案--------------------with就是设定作用域。
例子中在with(thisform){}中,作用域为thisform, email等价于 thisform.email
不过不建议这样使用