将第一个选项移动到第二个选择框中的过程。(移动选项与移除选项相似,即会重置每一个选项的index属性)
<
script
>
var
textbox1=
document.
getElementById(
"selectid");
var
textbox2=
document.
getElementById(
"selectid");
textbox2.
appendChild(
textbox1.
option[
0]);
<
/
script
>
<
body
>
<
form
action=
"http://www.baidu.com"
>
<
select
name=
""
id=
"selectid"
name=
"location"
>
<
option
value=
"q1"
>11
</
option
>
<
option
value=
"q2"
>22
</
option
>
<
option
value=
"q3"
>33
</
option
>
</
select
>
</
form
>
</
body
>
<
script
>
var
textbox=
document.
getElementById(
"selectid");
var
optionToMove=
textbox.
options[
1];
var
textbox=
document.
getElementById(
"selectid");
textbox.
insertBefore(
optionToMove,
textbox.
options[
optionToMove.
index-
1]);
//向前移动一个选项
textbox.
insertBefore(
optionToMove,
textbox.
options[
optionToMove.
index+
2]);
//向后移动一个选项
<
/
script
>