https://zhidao.baidu.com/question/385662806.html
js如何控制select标签哪个被选中
我要触发一个方法,里面执行select标签设置为默认的第一个option,如何操作?
我是这么写的,不知道哪里错了
document.getElementById("test“).options[0].selected=true;
我是这么写的,不知道哪里错了
document.getElementById("test“).options[0].selected=true;
发布于2015-07-11 17:15
最佳答案
JS 控制select选中项,代码如下:
|
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
26
27
28
|
<html> <script type="text/javascript"> var selectedValue = '<%= request.getAttribute("line")%>'; function changeSelected(){ jsSelectItemByValue(document.getElementById("mySelect"),selectedValue); } function jsSelectItemByValue(objSelect,objItemText) { for(var i=0;i<objSelect.options.length;i++) { if(objSelect.options[i].value == objItemText) { objSelect.options[i].selected = true; break; } } } </script> <body onload="changeSelected()"> <select id="mySelect" name="mySelect"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> </body> </html> |
delphi lazarus opengl
网页操作自动化, 图像分析破解,游戏开发
