select object

select object

A <select> tag corresponds to a select object.

select object properties

  • options[]: Set or return the <option> tag in the drop-down list array.

  • selectedIndex: Set or select the index number of the specified <option>.

  • length: Specify the number of <option> tags in the drop-down list.

  • name: element name.

option object

An <option> tag corresponds to an option object.

option object attribute

  • text: refers to the text between <option> and </option> .

  • value: refers to the attribute of the <option> tag.

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8" />
    <title>php.cn</title>
    <script>
        window.onload=function(){
            var Form = document.form;
            Form.city.options[2].text = "合肥";
            alert(Form.city.options[2].text);
        }
    </script>
</head>
<body>
    <form name="form" method="post" action="">
        城市:
        <select name="city">
            <option value="0">北京</option>
            <option value="1">上海</option>
            <option value="2">深圳</option>
        </select>
    </form>
</body>
</html>
Continuing Learning
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>php.cn</title>
<script>
window.onload=function(){
var Form = document.form;
Form.city.options[2].text = "";
alert(Form.city.options[2].text);
}
</script>
</head>
<body>
<form name="form" method="post" action="">
<select name="city">
<option value="0"></option>
<option value="1"></option>
<option value="2"></option>
</select>
</form>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
submitReset Code
图片放大关闭