javascript做二級聯動
系統
1917 0
<%
...
@pagecontentType
=
"
text/html;charset=UTF-8
"
%>
<
html
>
<
head
>
<
title
>
Thisisatest!
</
title
>
</
head
>
<
body
>
<
form
name
="frm"
>
<
select
name
="s1"
onChange
="redirec(document.frm.s1.options.selectedIndex)"
>
<
option
selected
>
請選擇
</
option
>
<
option
value
="1"
>
腳本語言
</
option
>
<
option
value
="2"
>
高級語言
</
option
>
<
option
value
="3"
>
其他語言
</
option
>
</
select
>
<
select
name
="s2"
>
<
option
value
="請選擇"
selected
>
請選擇
</
option
>
</
select
>
</
form
>
<
script
language
="javascript"
>
...
//
獲取一級菜單長度
var
select1_len
=
document.frm.s1.options.length;
var
select2
=
new
Array(select1_len);
//
把一級菜單都設為數組
for
(i
=
0
;i
<
select1_len;i
++
)
...
{select2[i]
=
new
Array();
}
//
定義基本選項
select2[
0
][
0
]
=
new
Option(
"
請選擇
"
,
"
"
);
select2[
1
][
0
]
=
new
Option(
"
PHP
"
,
"
"
);
select2[
1
][
1
]
=
new
Option(
"
ASP
"
,
"
"
);
select2[
1
][
2
]
=
new
Option(
"
JSP
"
,
"
"
);
select2[
2
][
0
]
=
new
Option(
"
C/C++
"
,
"
"
);
select2[
2
][
1
]
=
new
Option(
"
Java
"
,
"
"
);
select2[
2
][
2
]
=
new
Option(
"
C#
"
,
"
"
);
select2[
2
][
3
]
=
new
Option(
"
hibernate
"
,
"
"
);
select2[
3
][
0
]
=
new
Option(
"
Perl
"
,
"
"
);
select2[
3
][
1
]
=
new
Option(
"
Ruby
"
,
"
"
);
select2[
3
][
2
]
=
new
Option(
"
Python
"
,
"
"
);
//
聯動函數
function
redirec(x)
...
{
var
temp
=
document.frm.s2;
for
(i
=
0
;i
<
select2[x].length;i
++
)
...
{
temp.options[i]
=
new
Option(select2[x][i].text,select2[x][i].value);
}
temp.options[
0
].selected
=
true
;
}
</
script
>
</
body
>
fdsafdsf
</
html
>
javascript做二級聯動
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元