javascript中with(thisform)是什么意思

GOD_cheng 2011-07-18 10:17:57
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>
...全文
646 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuwenyayanzi 2013-09-08
  • 打赏
  • 举报
回复
GOD_cheng 2011-07-18
  • 打赏
  • 举报
回复
哦,明白了,谢谢各位高手指点!
MadEric 2011-07-18
  • 打赏
  • 举报
回复
with就是设定作用域。
例子中在with(thisform){}中,作用域为thisform, email等价于 thisform.email
不过不建议这样使用
GOD_cheng 2011-07-18
  • 打赏
  • 举报
回复
with是不是不建议使用在javascript中?
挨踢直男 2011-07-18
  • 打赏
  • 举报
回复
thisform.email
你本来要这么写引用email
加了with就不用了
直接 email就可以了
a260881071 2011-07-18
  • 打赏
  • 举报
回复
function validate_form(thisform)
{

if (validate_required(thisform.email,"Email must be filled out!")==false)
{thisform.email.focus();return false}
}






--------------------------------------帅签分割线-------------------------------------------------
a260881071 2011-07-18
  • 打赏
  • 举报
回复
http://www.w3school.com.cn/js/pro_js_statements_with.asp

这里是with的用法




--------------------------------------帅签分割线-------------------------------------------------

87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧