87,993
社区成员
发帖
与我相关
我的任务
分享
选择任何项都能换
谢谢大哥帮忙!
<select id="select1">
<option value="0">第1项</option>
<option value="1">第2项</option>
<option value="2">第3项</option>
<option value="3">第4项</option>
</select>
<select id="select2">
<option value="0">第8项</option>
<option value="1">第9项</option>
<option value="2">第10项</option>
<option value="3">第11项</option>
</select>
<input type="button" value="换" onclick="swap();" />
<script type="text/javascript">
function swap() {
var t1 = document.getElementById("select1");
var t2 = document.getElementById("select2");
var temp = t1.options[t1.selectedIndex].text;
t1.options[t1.selectedIndex].text = t2.options[t2.selectedIndex].text;
t2.options[t2.selectedIndex].text = temp;
}
</script>
非常感谢感谢!


<input type="text" id="text1" value="AAA" />
<input type="text" id="text2" value="BBB" />
<input type="button" value="换" onclick="swap();" />
<script type="text/javascript">
function swap() {
var t1 = document.getElementById("text1");
var t2 = document.getElementById("text2");
var temp = t1.value;
t1.value = t2.value;
t2.value = temp;
}
</script>