JS 获取select的value和text值
- <select id = "cityList" >
- <select id = "selectId" >
- <option value = "0">第0个</option>
- </select>
-
- <script>
- var selectObj = document.getElementById('selectId');
-
- selectId.add(new Option("第一个","1"))
- selectId.add(new Option("第二个","2"))
-
- selectId.add(new Option("第三个","3"))
- selectId.add(new Option("第四个","4"))
-
- selectId.onchange = function(){
-
- alert(selectObj.value);
- alert(selectObj.options[selectObj.selectedIndex].text);
-
- alert(selectId.value);
- alert(selectId.options[selectId.selectedIndex].text);
-
- alert(this.value);
- alert(this.options[this.selectedIndex].text);
- };
- </script>
有话要说