6.使用重置按鈕
<form name=form1> <input type=reset name=reset1 value="rest form"> </form> <script> document.write("表單reset1的類型:"+document.form1.reset1.type+"<br>") document.write("表單reset1的名稱:"+document.form1.reset1.name+"<br>") document.write("表單reset1的值:"+document.form1.reset1.value+"<br>") </script>
7.使用提交按鈕
<form name=form1> <input type=submit name=submit1 value="submit form"> </form> <script> document.write("表單submit1的類型:"+document.form1.submit1.type+"<br>") document.write("表單submit1的名稱:"+document.form1.submit1.name+"<br>") document.write("表單submit1的值:"+document.form1.submit1.value+"<br>") </script>
8.使用復(fù)選按鈕
<form name=form1> <input type=checkbox name=cb1 >computer savvy? </form> <script> document.write("表單cb1的類型:"+document.form1.cb1.type+"<br>") document.write("表單cb1是否被選擇?:"+document.form1.cb1.checked+"<br>") document.write("表單cb1的名稱:"+document.form1.cb1.name+"<br>") </script>
9.使用單選按鈕
<form name=form1> <input type=radio name=radio1>male <input type=radio name=radio1>female </form> <script> document.write("第一個(gè)按鈕被選擇"+document.form1.radio1[0].checked+"<br>") document.write("第二個(gè)按鈕被選擇"+document.form1.radio1[1].checked+"<br>") document.write("按鈕的名稱"+ document.form1.radio1[0].name+"<br>") document.write("按鈕的個(gè)數(shù)"+document.form1.radio1.length) </script>
10.使用選擇列表
<form name=form1> <select name=select1 size=4> <option name=option1 value=lon>london,England</option> <option name=option2 value=dub>Dublin,Ireland</option> </select> </form> <script> document.write("這個(gè)選擇列表的名稱"+document.form1.select1.name+"<br>") document.write("這個(gè)選擇列表的長(zhǎng)度"+document.form1.select1.length+"<br>") document.write("這個(gè)選擇列表當(dāng)前被選擇的索引號(hào)"+document.form1.select1.selectedIndex+"<br>") document.write("這個(gè)選擇列表的尺寸"+document.form1.select1.size+"<br>") </script>
11.驗(yàn)證表單的有效性
<script> function validate(){ if(document.form1.text1.value!='1'||'2'||'3'||'4'){ alert("請(qǐng)輸入1~4的整數(shù)") } } </script> <form name=form1> 請(qǐng)輸入1~4的整數(shù): <input type=text name=text1 size=4 onchange=validate()> </form>
12.控制表單焦點(diǎn)
<form name=form1> <input type=text name=text1 value=where is you focus?><br> <input type=text name=text2 value=is there?><br> <input type=text name=text3 value=or maybe here?><br> <input type=button name=button1 value="text box #1" onclick=document.form1.text1.focus()><br> <input type=button name=button2 value="text box #2" onclick=document.form1.text2.focus()><br> <input type=button name=button3 value="text box #3" onclick=document.form1.text3.focus()><br> </form>
第十三章 使用分欄
第十四章 使用navigator
1.使用navigator對(duì)象
<script> document.write("navigator對(duì)象的屬性"+"<br>") document.write("appcodename:"+navigator.appCodeName+"<br>") document.write("appname::"+navigator.appName+"<br>") document.write("appversion:"+navigator.appVersion+"<br>") document.write("platform:"+navigator.platform+"<br>") document.write("userAgent:"+navigator.userAgent+"<br>") </script> <script> document.write("navigator對(duì)象的方法"+"<br>") document.write("javaEnabled():"+navigator.javaEnabled()) </script>
2.檢查用戶的瀏覽器
<script> if(navigator.appName.indexOf("Microsoft")!=-1){ document.write("用戶瀏覽器是微軟的IE瀏覽器"+"<br>")} else if(navigator.appName.indexOf("Netscape")!=-1){ document.write("用戶瀏覽器是netscape的netscape瀏覽器"+"<br>")} if(navigator.appVersion.indexOf("4.0")!=-1){ document.write("you are using a version 4.0compatible browser") } else{ document.write("this browser is not 4.0 compliant")} </script>
3.檢測(cè)用戶的操作系統(tǒng)
<script> if (navigator.platform.indexOf("win32")!=-1){ document.write("you are using a computer running windows 95 or highter")} else{ document.write("this computer is not running windows 95 or higher")} </script>
4.使用location對(duì)象
<script> document.write("location對(duì)象的屬性"+"<br>") document.write("hash"+location.hash+"<br>") document.write("hostname"+location.hostname+"<br>") document.write("host"+location.host+"<br>") document.write("href"+location.href+"<br>") document.write("port"+location.port+"<br>") document.write("search"+location.search+"<br>") </script>
重新加載網(wǎng)頁(yè) <form name=form1> <input type=button name=button1 value=重新加載本頁(yè) onclick=location.reload> </form>
5.使用cookie
<script> finction makecookie(){ if(!document.cookie){ name=prompt("請(qǐng)輸入你的姓名"); document.cookie="name="+name+";";} } </script>
<body onload=makecookie()> <script> function makecookie(){ if(!document.cookie){ name=prompt("請(qǐng)輸入你的姓名") document.cookie="name="+name+";"; namestart=document.cookie.indexOf("="); nameend=document.cookieindexOf(";"); document.writeln("your name is:"+document.cookie.substring(namestart+1,nameend)+",br>") } } </script>
出處:藍(lán)色理想
責(zé)任編輯:moby
上一頁(yè) 事半功倍之Javascript [7] 下一頁(yè)
◎進(jìn)入論壇網(wǎng)頁(yè)制作、網(wǎng)站綜合版塊參加討論
|