js经典试题

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1.实现列表框元素的左右移动。move.htmlscripttype=text/javascriptfunctionmove(a,b){varaObj=document.getElementById(a);varbObj=document.getElementById(b);for(vari=0;iaObj.length;i++){if(aObj[i].selected){varopt=newOption(aObj[i].text,aObj[i].value);bObj.add(opt);aObj.remove(i);i--;}}}/scripttablewidth=40%border=1bgcolor=#cececetrtdselectid=leftsize=6multipleoptionvalue=1增加简历/optionoptionvalue=2删除简历/optionoptionvalue=3修改简历/optionoptionvalue=4列表简历/option/select/tdtdinputtype=buttonvalue=onclick=move('left','right')brinputtype=buttonvalue=onclick=move('right','left')/tdtdselectid=rightsize=6multiplestyle=width:80px/select/td/tr/table2.实现姓名和学号每隔一秒钟互换的效果。change.htmlscript//每隔一秒钟学号和姓名互换vari=0;window.onload=change;setInterval('change()',1000);functionchange(){if(i%2){document.getElementById(result).innerHTML='姓名:张三';}else{document.getElementById(result).innerHTML='学号:0303003';}i++;}/scriptdivid=result/div3.动态显示当前日期时间。datetime.htmlscriptwindow.onload=init;setInterval('init()',1000);functioninit(){vardate=newDate();varyear=date.getYear();varmonth=date.getMonth()+1;if(month10)month=0+month;varday=date.getDate();if(day10)day=0+day;varhour=date.getHours();if(hour10)hour=0+hour;varminute=date.getMinutes();if(minute10)minute=0+minute;varsecond=date.getSeconds();if(second10)second=0+second;vardateTime=year+-+month+-+day++hour+:+minute+:+second;document.getElementById(dateTime).value=dateTime;}/scriptinputtype=textname=dateTimereadonly4.实现全选和反选。check.htmlscript//全选functioncheckAll(){varchAll=document.getElementById(ckAll);varitems=document.getElementsByName(item);for(vari=0;iitems.length;i++){items[i].checked=chAll.checked;}}//反选functionreverseAll(){varrevAll=document.getElementById(revAll);varitems=document.getElementsByName(item);for(vari=0;iitems.length;i++){items[i].checked=!items[i].checked;}}/script全选inputtype=checkboxname=ckAllonclick=checkAll()/反选inputtype=checkboxname=revAllonclick=reverseAll()brinputtype=checkboxname=itembrinputtype=checkboxname=itembrinputtype=checkboxname=itembrinputtype=checkboxname=itembrinputtype=checkboxname=itembr5.实现省市二级联动connAction.htmlscriptlanguage=javascript!--vargroup;window.onload=init;functioninit(){varlen=document.getElementById(province).length;group=newArray(len);for(vari=0;ilen;i++){group[i]=newArray();}group[0][0]=newOption(北京,北京);group[0][1]=newOption(上海,上海);group[0][2]=newOption(天津,天津);group[0][3]=newOption(重庆,重庆);group[1][0]=newOption(武汉,武汉);group[1][1]=newOption(鄂州,鄂州);group[1][2]=newOption(孝感,孝感);group[1][3]=newOption(黄冈,黄冈);group[1][4]=newOption(黄石,黄石);group[2][0]=newOption(石家庄,石家庄);group[2][1]=newOption(保定,保定);group[2][2]=newOption(张家口,张家口);group[2][3]=newOption(承德,承德);group[3][0]=newOption(长沙,长沙);group[3][1]=newOption(湘潭,湘潭);group[3][2]=newOption(株州,株州);group[3][3]=newOption(衡阳,衡阳);group[3][4]=newOption(岳阳,岳阳);}functionconnAction(x){varcity=document.getElementById(city);for(varm=city.length-1;m0;m--){city.options[m]=null;}for(i=0;igroup[x].length;i++){city.options[i]=newOption(group[x][i].text,group[x][i].value);}}//--/scriptselectname=provinceonChange=connAction(this.selectedIndex)optionvalue=直辖市selected直辖市/optionoptionvalue=湖北湖北/optionoptionvalue=河北河北/optionoptionvalue=湖南湖南/option/select省selectname=cityoptionvalue=北京selected北京/optionoptionvalue=上海上海/optionoptionvalue=天津天津/optionoptionvalue=重庆重庆/option/select市6.实现基本的表单验证功能formCheck.htmlHTMLHEADTITLEFormCheck/TITLEMETAhttp-equiv=Content-Typecontent=text/html;charset=gb2312STYLETD{FONT-SIZE:12px;COLOR:#333333}/STYLESCRIPTlanguage=JavaScripttype=text/JavaScriptsrc=formcheck.js/SCRIPTSCRIPTlanguage=JavaScript!--functionformCheck(){if(!isIdno(document.testForm.id.value)){alert(身份证号码输入有误!要求只能输入数字,长度为16或18位。);document.testForm.id.focus();returnfalse;}if(!isChinaTel(document.testForm.tel.value)){alert(固定电话号码输入有误!合法的格式为:区号-电话号码。);document.testForm.tel.focus();returnfalse;}if(!isChinaMob(document.testForm.mobi.value)){alert(移动电话号码输入有误!);document.testForm.mobi.focus();returnfalse;}if(!isMail(document.testForm.mail.value)){alert(邮箱输入有误!);document.testForm.mail.focus();returnfalse;}if(!isPostCode(document.testForm.post.value)){alert(邮政编码输入有误!要求只能输入数字,长度为6位。);document.testForm.post.focus();returnfalse;}if(!isNLU(document.testForm.nlu.value)){alert(该域只能输入数字、字母或下划线!);document.testForm.nlu.focus();returnfalse;}varlen=getLength(document.testForm.leng.value);if(len4||len6){alert(该域要求输入长度范围是4至6个字符!);document.testForm.leng.focus();returnfalse;}}//--/SCRIPTBODYtext=#000000bgColor=#ffffffonload=focusInFirst()CENTERBFONTface=Geneva,Arial,Helvetica,san-serifcolor=#ff6600size=4ThesampleofFormCheck/FONT/BFONTface=Arial,Helvetica,sans-serifsize=2(ByRoczhao)/FONTHRwidth=60%color=#000000noShadeSIZE=1FORMname=testFormonsubmit=returnformCheck();method=postTABLEcellSpacing=0cellPadding=0width=500border=1TBODYTRTDwidth=182height=25身份证:/TDTDwidth=312INPU

1 / 8
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功