本文实例讲述了js显示下拉列表框内全部元素的方法。分享给大家供大家参考。具体如下:
; D P" y) m$ Y4 k下面的js代码可以通过alert框显示指定下拉列表的全部元素0 y, J0 o& _9 B5 W. S5 M+ b
<!doctype html>, M4 t4 z9 Q- L) U& `/ M9 s
<html>+ ~8 k/ J1 D3 V4 e+ I
<head># L: L* @! s- Z9 w
<script>" H' `! c- P H
function getoptions()
0 A7 W; d0 \; U{3 I9 |& M" E& b, B; u
var x=document.getelementbyid(myselect);
i) p. \- p w& v! r: nvar txt=all options: ;
' C( K" t6 K1 y7 K+ h5 [var i;8 }! A2 ?8 }: Y D# U& I- h4 E4 X
for (i=0;i<x.length;i++)
" B# G" k E7 s9 h* c0 s{
1 c( B. f5 K) n! ~/ a0 ~txt=txt + \n + x.options[i].text;
c3 U3 S3 L% h}
5 x% a2 I- I3 ]4 Y- g" F+ Walert(txt);
* p: A9 ~: L, L) ^ } r, k}
7 I. r. G, n9 ~7 S; F9 P</script>
# I: i& [, c! Y( \- |" W- Y( {, w/ V</head>+ y5 d; F$ D9 W
<body>- A0 v# u' E) |- K9 ]: |
<form>
9 q# l f; i: j$ ?) P% Fselect your favorite fruit:
. t1 M! S6 D) C1 ^# _) Q<select id=myselect>; Q! ^" H9 K6 P8 A) d" K
<option>apple</option>
5 \0 B" L R; V# @7 A<option>orange</option>3 ^; r6 T% R! q' N- y( B [
<option>pineapple</option>4 p) a. {, i) {" |
<option>banana</option>- H. t9 G" \9 I2 U8 z: {
</select>- Z- g3 N3 _# s6 Q% {$ \7 M
<br><br>
$ A) R+ @0 D4 G: Y7 [<input type=button onclick=getoptions()
6 g4 T, e2 Q: G- h+ Y9 wvalue=output all options>* d( T* L3 i7 C7 ^* ^$ U7 g, _
</form>
* d. N. B. Q# s/ X& k</body>" ^+ L$ a; G4 y* g, E
</html>
, g! ?' P& y" {4 ~, K+ U8 i9 f- A) ~4 b& r+ a2 {
更多网页制作信息请查看: 网页制作 |
|