select对象和option对象联合应用

一 代码
1、在页面中添加一个2行3列的表格,在左右两边的单元格中添加滚动列表,在中间的单元格中添加两个按钮。代码如下:
<form name="form1" method="post" action="">
<table width="380" border="0" align="center" cellpadding="0" cellspacing="0">
 <tr>
 <td width="150"><table width="150" border="0" cellpadding="1" cellspacing="1" bgcolor="#CAFAFC">
 <tr>
 <td height="25" background="images/bg.jpg" bgcolor="#FFFFFF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;任务地区1</td>
 </tr>
 <tr>
 <td align="center" bgcolor="#FFFFFF"><select name="sel_place1" size="6" multiple id="sel_place1" style="width:100px " >
 <option value="sel1">甘肃省</option>
 <option value="sel2">辽宁省</option>
 <option value="sel3">黑龙江省</option>
 <option value="sel4">吉林省</option>
 <option value="sel5">浙江省</option>
 </select></td>
 </tr>
 </table></td>
 <td width="80" align="center" valign="bottom"><input name="sure1" type="button" id="sure1"
 onClick="allsel(document.form1.sel_place2,document.form1.sel_place1);" value="<<">
 &nbsp;
 <input name="sure2" type="button" id="sure2"
 onClick="allsel(document.form1.sel_place1,document.form1.sel_place2);" value=">>" align="center" height="2"></td>
 <td width="150"><table width="150" border="0" cellpadding="1" cellspacing="1" bgcolor="#CAFAFC">
 <tr>
 <td height="25" background="images/bg.jpg" bgcolor="#FFFFFF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;任务地区2</td>
 </tr>
 <tr>
 <td align="center" bgcolor="#FFFFFF"><select name="sel_place2" size="6" multiple id="sel_place2" style="width:100px ">
 </select></td>
 </tr>
 </table></td>
 </tr>
</table>
</form>
 
2、编写用于实现在滚动列表框中进行选项移除的JavaScript代码:
<script language="javascript">
function allsel(n1,n2)
{
 while(n1.selectedIndex!=-1)
 {
  var indx=n1.selectedIndex;
  var t=n1.options[indx].text;
  n2.options.add(new Option(t));
  n1.remove(indx);
 }
}
</script>
 
二 运行效果


 

猜你喜欢

转载自cakin24.iteye.com/blog/2359561