JS复习资料.docx
- 文档编号:30146506
- 上传时间:2023-08-05
- 格式:DOCX
- 页数:17
- 大小:18.36KB
JS复习资料.docx
《JS复习资料.docx》由会员分享,可在线阅读,更多相关《JS复习资料.docx(17页珍藏版)》请在冰豆网上搜索。
JS复习资料
JavaScript复习大纲
考点一:
date对象
1.年龄的计算:
functiongetbth()
{vary=document.getElementById("year").value;
varm=document.getElementById("month").value;
vard=document.getElementById("day").value;
varbday=newDate(y,m,d);
vard=newDate();
vardays=parseInt((d.getTime()-bday.getTime())/1000/60/60/24/365);
document.getElementById("age").innerHTML="
";
}
2.显示当前窗体时间
functionnowTime()
{
varnow=newDate();
document.getElementById("nowtime").innerHTML=now.toLocaleString();
setTimeout("nowTime()",1000);
}
3.记录多少天之后的日期:
functionaddtime(){
vartime=document.myform.addnum.value;
varaddtime=newDate();
varnewtime=addtime.getTime()+(time*24*60*60*1000);
addtime.setTime(newtime);
document.myform.time.value=addtime.toLocaleString();}
考点二:
表单验证
1.案例一:
用户名不能为空,开户账户省份不能为空,开户账户城市不能为空
functioncheckForm_user()
{
if(document.myform.txtUserName.value.length==0)
{
alert("用户名不能为空!
");
document.myform.txtUserName.focus();
returnfalse;
}
elsereturntrue;
}
functioncheckForm_province()
{
if(document.myform.selProvince.value.length==0)
{
alert("请选择开户账号的省份!
");
document.myform.selProvince.focus();
returnfalse;
}
elsereturntrue;
}
functioncheckForm_city()
{
if(document.myform.selCity.value.length==0)
{
alert("请选择开户账号的城市!
");
document.myform.selCity.focus();
returnfalse;
}
elsereturntrue;
}
functioncheckForm()
{
if(checkForm_user()&&checkForm_province()&&checkForm_city())
{
returntrue;
}
elsereturnfalse;
}
2.及时提示错误,用户名不能为空,密码长度不能少于6位,密码和验证密码不一致,电子邮件不能为空!
必须包含@符号,必须包含.符号
functioncheckPass1()
{
varmyDiv=document.getElementById("passError");
myDiv.innerHTML="";
varstrPass=document.userfrm.pass.value;
if(strPass.length<6)
myDiv.innerHTML="
";
}
functioncheckPass2()
{
varmyDiv=document.getElementById("passError2");
myDiv.innerHTML="";
varstrPass=document.userfrm.pass.value;
if(strPass.length<6)
{myDiv.innerHTML="
";}
if(document.getElementById("passError")!
=document.getElementById("passError2"))
{myDiv.innerHTML+="
";}
}
functioncheckEmail()
{
varmyDiv=document.getElementById("emailError");
myDiv.innerHTML="";
varstrEmail=document.userfrm.email.value;
if(strEmail.length==0)
{
myDiv.innerHTML="
";
return;
}
if(strEmail.indexOf("@",0)==-1)
{
myDiv.innerHTML="
";
}
if(strEmail.indexOf(".",0)==-1)
{
myDiv.innerHTML+="
";
}}
考点三:
弹出窗口,窗口无菜单栏、工具栏、状态栏、地址栏、滚动条、宽度500px,高度550px。
functiongetaddress(){
varaddress=showModalDialog("address.html","","dialogWidth:
550px;dialogHeight:
550px");
document.myform.address.value=address;}
考点四:
切换广告和图片自动跳转和幻灯片播放图片切换广告
functionshow(d1){
for(vari=1;i<5;i++){
if(i==d1)
document.getElementById('div'+d1).style.display='block';//当前图片示
else
document.getElementById('div'+i).style.display='none';//隐藏其他图片层
}
}
absolute;left: 200px;top: 60px;width: 361px"> block;"id="div1"border="0"> none;"id="div2"border="0"> none;"id="div3"border="0"> none;"id="div4"border="0">
absolute;left: 440px;top: 230px;"align="center"> show (1)">1 show (2)">2 show(3)">3 show(4)">4
图片自动跳转
varoldnum=1;
functionmyturn()
{varnewnum=Math.round(Math.random()*4);
if(newnum==0)
{
newnum=4;
}
document.getElementById(oldnum).style.display="none";
document.getElementById(newnum).style.display="block";
oldnum=newnum;
setTimeout("myturn()",1000);}
document.write("
document.getElementById("a").innerHTML="
none"src="T1gZt0XhxrXXXXXXXX-80-80.png"width="80"height="80"> none"src="T1v0p0XhJeXXXXXXXX-80-80.jpg"width="80"height="80"> none"src="T1XdJ0XntaXXXXXXXX-80-80.jpg"width="80"height="80">