- var t = document.getElementById("select1");
- var selectValue=t.options[t.selectedIndex].value;//获取select的值
- var t1 = document.getElementById("select2");
- for(i=0;i<t1.length;i++){//给select赋值
- if(selectValue==t.options[i].value){
- t1.options[i].selected=true
- }
- }
- 第二种方法,赋值是一样
- <script>
- function getSelectValue(){
- var selectCount = document.getElementById("select1").options;
- for(var i = 0 ; i<selectCount.length;i++){
- if(selectCount[i].selected){
- alert(selectCount[i].value);
- }
- }
- }
- </script>
- <select id="select1" name="select1">
- <option value="0">0</option>
- <option value="1">1</option>
- <option value="2">2</option>
- </select>
- <input type="button" id="button1" value="submit" onclick="getSelectValue()"/>