js动态的把左边列表添加到右边,可删除。

<!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>
  <title> new document </title>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  <meta name="author" content="" />
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <link rel="stylesheet" type="text/css" href="" />
  <style type="text/css"></style>
  <script type="text/javascript"></script>
 </head>

 <body>
  <table width="95%" cellpadding="0" align="center" class="listshow" border="1" cellspacing="0">
		<tr>
  		<td colspan="4" align="center">选择分包</td>
  	</tr>
		<tr>
 			<td class="black" width="30%" align="center" height="150">
 				<select id="fb_list" multiple="multiple" style="text-align:center;width:300px;height:150px;">
     </select> 
    </td>
    <td align="center" width="5%">
    <input type="button" id="add" value="添加>>" />
      <br/>
      <br/>
      <input type="button" id="delete" value="<<删除" />
    </td>
    <td class="black" width="30%" align="center">
    <select id="select_list" multiple="multiple" style=" text-align:center;width:300px;height:150px;">
      </select>
    </td>
		</tr>
</table>

<script src="jquery-1.7.1.min.js"></script>
<script>
/**
 *动态的给左边的下拉列表创建选项
 *具体情况可以从数据库读取数据动态创建选项
 */
	$(document).ready(function(){
    for(var i=1;i<=5;i  )
    {
       $("#fb_list").append("<option value='" i "'>公开招标小型机采购00" i "</option>"); 
    }
		})
	$(function(){
  	$("#add").click(function(){
       if($("#fb_list option:selected").length>0)
       {
           $("#fb_list option:selected").each(function(){
              $("#select_list").append("<option value='" $(this).val() "'>" $(this).text() "</option");
              $(this).remove(); 
           })
       }
       else
       {
           alert("请选择要添加的分包!");
       }
   })
})
        $(function(){
      $("#delete").click(function(){
           if($("#select_list option:selected").length>0)
           {
               $("#select_list option:selected").each(function(){
                     $("#fb_list").append("<option value='" $(this).val() "'>" $(this).text() "</option");
                     $(this).remove(); 
               })
           }
           else
           {
               alert("请选择要删除的分包!");
           }
     })
})
</script>
 </body>
</html>

 


更多专业前端知识,请上 【猿2048】www.mk2048.com
您可以使用 JavaScript 和 HTML 实现这个功能。具体步骤如下: 1. 在 HTML 中创建两个 select 元素,一个用于左侧选项,一个用于右侧选项。 ```html <select id="leftSelect"> <option value="option1">选项1</option> <option value="option2">选项2</option> <option value="option3">选项3</option> </select> <select id="rightSelect"> </select> ``` 2. 创建一个按钮,用于移动选项。当点击按钮时,将左侧选中的选项移动到右侧 select 中。 ```html <button onclick="moveOption()">移动选项</button> ``` 3. 在 JavaScript 中实现 moveOption() 函数,用于移动选项。该函数应该获取左侧 select 中选中的选项,将其添加到右侧 select 中,并从左侧 select 中删除。 ```javascript function moveOption() { var leftSelect = document.getElementById("leftSelect"); var rightSelect = document.getElementById("rightSelect"); // 获取选中的选项 var selectedOption = leftSelect.options[leftSelect.selectedIndex]; // 添加到右侧 select 中 rightSelect.appendChild(selectedOption); // 从左侧 select 中删除 leftSelect.remove(leftSelect.selectedIndex); } ``` 4. 最后,您可以根据需要添加样式和其他功能来完善这个功能。 完整的 HTML 和 JavaScript 代码如下: ```html <select id="leftSelect"> <option value="option1">选项1</option> <option value="option2">选项2</option> <option value="option3">选项3</option> </select> <select id="rightSelect"> </select> <button onclick="moveOption()">移动选项</button> <script> function moveOption() { var leftSelect = document.getElementById("leftSelect"); var rightSelect = document.getElementById("rightSelect"); // 获取选中的选项 var selectedOption = leftSelect.options[leftSelect.selectedIndex]; // 添加到右侧 select 中 rightSelect.appendChild(selectedOption); // 从左侧 select 中删除 leftSelect.remove(leftSelect.selectedIndex); } </script> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值