欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JS的with语句的简单应用

程序员文章站 2024-02-20 11:17:16
...

例一:
<html>
<head>
<base href="<%=basePath%>">

<title>登录页面</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

<script type="text/javascript">
function RegisterSubmit(){
//获取整个name为Register的form对象
with(document.Register){
var loginname=username.value;
var loginpasswd=passwd.value;
if(loginname==null || loginname==""){
alert("请填写用户名");
}else if(loginpasswd==null || loginpasswd==""){
alert("请填写密码");
}else{
document.Register.submit();
}
}
}
</script>
</head>
<body>
<form action="servlet/LoginServlet" name="Register" method="post">
<center>
<table typle="text-align:cunter" width="590" border="0" bgcolor="#8FBC8F">
<tr><td><p align="right">用户名:</p></td>
<td align="left"><input type="text" name="username" style="width:120px"/></td>
</tr>
<tr><td><p align="right">密  码:</p></td>
<td align="left"><input type="password" name="passwd" style="width:120px"/></td>
</tr>
<tr rowspan="2">
<td align="right"><input type="button" value="提交" onclick="RegisterSubmit()"/> </td>
<td align="left"><input type="reset" value="重置"/></td>
</tr>
</table>
</center>
</form>
</body>
</html>
例二:
<script language="javascript">
<!--
function Lakers() {
this.name = "kobe bryant";
this.age = "28";
this.gender = "boy";
}
var people=new Lakers();
with(people)
{
var str = "姓名: " + name + "<br>";
str += "年龄:" + age + "<br>";
str += "性别:" + gender;
document.write(str);
}
//-->
</script>
相关标签: js with