下拉框例子

来源:互联网 发布:js转化日期yyyymmdd 编辑:程序博客网 时间:2024/05/16 19:28

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script src="jquery-1.3.1.js" type="text/javascript" ></script>
<script>
$(function(){
  $("#add").click(function(){
      var sel=$("#select1 option:selected");
   var del=sel.remove();
   del.appendTo("#select2");
  
  })
  $("#select1").dblclick(function(){
     var dd= $("option:selected",this);
  dd.appendTo("#select2");
  })
  $("#add_all").click(function(){
      var ss=$("#select1 option");
   ss.appendTo("#select2");
 
  })
  $("#remove").click(function(){
     var xx= $("#select2 option:selected");
  xx.appendTo("#select1");
 
  })
  $("#remove_all").click(function(){
    var zz=$("#select2 option");
 zz.appendTo("#select1");
 
  })
  $("#select2").dblclick(function(){
     var as=$("option:selected",this);
  as.appendTo("#select1");
  })

})

</script>
<style>
.content
{
display:block;
float:left;
width:150px;
}
.centent
{
display:block;
float:left;
width:150px;
}
span
{
background:#C3F5A2;
border:1px solid #d4a5c3;
margin:5px;
margin-left:5px;
padding:1px;
}
</style>
</head>

<body>
<div class="content">
<select multiple="multiple" id="select1" style="width:100px; height:160px;">
<option value="1">选项1</option>
<option value="2">选项2</option>
<option value="3">选项3</option>
<option value="4">选项4</option>
<option value="5">选项5</option>
<option value="6">选项6</option>
<option value="7">选项7</option>
<option value="8">选项8</option>
</select>
<div>
    <span id="add">选中添加到右边&gt;&gt;</span>
    <span id="add_all">全部添加到右边&gt;&gt;</span>
</div>
</div>
<div class="centent">
  <select multiple="multiple" id="select2" style="width:100px; height:160px;">
 
  </select>
 
  <div>
  <span id="remove">&lt;&lt;选中删除到左边</span>
    <span id="remove_all">&lt;&lt;全部删除到左边</span>
 
  </div>

</div>
</body>
</html>

原创粉丝点击