1、通过修改select的value值

 1 <input type="button" />
 2 <select name="select" >
 3     <option value="1">aa</option>
 4     <option value="a">bb</option>
 5     <option value="c">cc</option>
 6 </select>
 7 <script type="text/javascript">
 8 //点击按钮,让第二项选中
 9     document.getElementById('btn').onclick=function(){
10         document.getElementById('select').value="a";
11     }    
12 </script>

 2、通过修改option的selected属性

 1 <input type="button"     />
 2 <select name="select" >
 3     <option value="1">aa</option>
 4     <option value="a">bb</option>
 5     <option value="c">cc</option>
 6 </select>
 7 <script type="text/javascript">
 8     document.getElementById('btn').onclick=function(){
      //点击按钮,让第二个选项选中 9 var options = document.getElementById('select').children; 10 options[1].selected=true; 11 }
12 </script>

 

相关文章:

  • 2021-08-22
  • 2022-12-23
  • 2021-08-31
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-10-25
  • 2021-10-22
  • 2022-12-23
相关资源
相似解决方案