练习:用户登录界面
代码:
<script type="text/javascript">
function check(){
var name=form1.user.value; //获取用户添加的用户名信息
var pwd=form1.pwd.value; //获取用户添加的密码信息
if((name=="")||(name=null)){ //判断用户名是否为空
alert("请输入用户名!");
form1.user.focus(); //用户名文本框获取焦点
return;
}else if((pwd=="")||(pwd=null)){//判断密码是否为空
alert("请输入密码!");
form1.pwd.focus(); //密码文本框获取焦点
}else{
form1.submit(); //提交表单
}
}
</script>
<body>
<form name="form1" method="post" action="">
<table border="1" cellspacing="0" cellpadding="0"
bordercolor="#FFFFFF" bordercolordark="#CCCCCC" bordercolorlight="#FFFFFF">
<tr>
<td height="30" colspan="2" bgcolor="antiquewhite">用户登录</td>
</tr>
<td width="59" height="30">用户名:</td>
<td width="162"><input name="user" type="text" class="user"></td>
<td height="30">密 码</td>
<td><input name="pwd" type="text" class="pwd"></td>
<td height="30" colspan="2" align="center">
<input name="button" type="button" class="btn_grey" value="登录" onclick="check()">
<input name="Submit2" type="reset" class="btn_grey" value="重置">
</td>
</table>
</form>
</body>
练习:星期获取系统
var now=new Date();
var day=now.getDay();
var week;
switch(day){
case 1: week="星期一"; break;
case 2: week="星期二"; break;
case 3: week="星期三"; break;
case 4: week="星期四"; break;
case 5: week="星期五"; break;
case 6: week="星期六"; break;
case 7: week="星期七"; break;
}
document.write("今天是"+week);
</script>