javascript級聯下拉式清單執行個體代碼(自寫)

來源:互聯網
上載者:User

Html dom 是指在w3c規範出現之前,各個瀏覽器支援的一些dom操作。
1,Select對象。
屬性
a,selectedIndex:使用者選擇的選項的下標,下標從0開始
b,length: 擷取或者設定選項的個數
c,options: 返回一個數組,數組元素是Option對象
2,Options對象
屬性:
a,text:選項的常值內容
b,value:選項的値
c,selected: 當該選項被選上,值為true,否則為false
小知識:建立一個Option對象 複製代碼 代碼如下:var op=new Option(text,value);

我寫的一個級聯下拉式清單:

代碼如下: 複製代碼 代碼如下:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
#d1 {
width: 400px;
height: 250px;
background-color: #FFE4B5;
margin: 40px auto;
}
#d1_head {
color: white;
font-size: 20px;
font-family: "Arial";
height: 24px;
background-color: bule;
}
#d1_content {
padding-left: 30px;
padding-top: 30px;
}
</style>
<script src="prototype-1.6.0.3.js"></script>
<script type="text/javascript">
function doAction(index) {
var arr = new Array;
arr[0] = [ new Option('--研究方向--', '-1') ];
arr[1] = [ new Option('商務英語', 'english1'),
new Option('英美文學', 'english2') ];
arr[2] = [ new Option('格線運算', 'computer1'),
new Option('電腦軟體', 'computer2'),
new Option('圖形計算', 'computer3') ];
$('s2').innerHTML = '';
for (i = 0; i < arr[index].length; i++) {
$('s2').options[i] = arr[index][i];
}
}
</script>
</head>
<body style="font-size:30px;">
<div id="d1">
<div id="d1_head">專業選擇</div>
<div id="d1_content">
<form>
<select naem="s1" id="s1" style="width:120px;"
onchange="doAction(this.selectedIndex);">
<option value="-1">--專業--</option>
<option value="english">--英語--</option>
<option value="computer">--電腦--</option>
</select> <select name="s2" id="s2" style="width:120px;">
<option value="-1">--研究方向--</option>
</select> <input type="submit" value="確認" />
</form>
</div>
</div>
</body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.