关于如何动态地在同一页面实现两个 < select > 互传 (s1 <==> s2)

 

关于如何动态地在同一页面实现两个<select>互传  (s1 <==> s2)
     
                     (jaklin )
    

    hello! 先祝大家中秋节快乐!

    我们常常会碰到这样一个问题: 如何将在同一页面上的一个<select>或<listbox>的值传到另一个<select>或<listbox>中 ?这是一个很烦人的问题。可是有时候你偏偏会遇到。 那什么办呢?

     下面是我“烟酒”了一个上午, 现贴上来让大家共享。 用的方法是很笨也挺麻烦。不过总是有点成就感的。呵呵!大家看看, 指点指点.....

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<script language="vbscript">

</script>
<body bgcolor="#ffffff">
<form name="form1"  action="test01.asp" target="_self">
<p><TEXTAREA id=text01 name=text01></TEXTAREA></p>
<table>
   <tr>
     <td>
       <select name="select1" language="javascript" size=5>
    <option value=11111>11111</option>
    <option value=22222>22222</option>
    <option value=33333>33333</option>
       </select>
     </td>
     <td>
    <label onClick=do_select()><font color=#ff00dc><u>->> </u></font> </label><br><br>
    <label onClick=do_select2()><font color=#ff00dc><u><<- </u></font> </label>
     </td>
    <%  
     str="function do_select() {" & vbCrlf & _
             "if (document.form1.select1.options.length > 0) {"&vbCrlf&_
         "var j=0;"&vbCrlf&_
         "for(var i=0;i<document.form1.select1.options.length;i++) {"&vbCrlf & _
         "if(document.form1.select1.options(i).selected) {"&vbCrlf& _
             "j=j+1; break" & vbCrlf & "}"&vbCrlf & "}"&vbCrlf& _
         "if (j > 0) {"&vbCrlf&_                    "document.form1.sel2.options[document.form1.sel2.options.length] = new Option(" &  _
              "document.form1.select1.options[document.form1.select1.selectedIndex].value,"  & _
              "document.form1.select1.options[document.form1.select1.selectedIndex].value);"& vbCrlf
    Response.Write "<td><SELECT id=sel2  name=sel2 size=5>"
    Response.Write "</select></td>"
          str=str&vbCrlf&"document.form1.select1.options[document.form1.select1.selectedIndex]=null;"&vbCrlf & _
    "if (document.form1.select1.options.length > 1) {"&vbCrlf   '&_
    str=str&vbCrlf & "}" & vbCrlf & "}" & vbCrlf& "}" & vbCrlf& "}" & vbCrlf
    Response.Write "<SCR"& "IPT LANGUAGE=""JavaScript"">" & vbCrlf
    Response.Write str & vbCrlf & "</SCR"&"IPT>"& vbCrlf
              
        %>
      
    <%
    str=""
    str="function do_select2() {" & vbCrlf & _
    "if (document.form1.sel2.options.length > 0) {"&vbCrlf&_
    "var j=0;"&vbCrlf&_
    "for(var i=0;i<document.form1.sel2.options.length;i++) {"&vbCrlf & _
    "if(document.form1.sel2.options(i).selected) {"&vbCrlf& _
    "j=j+1; break" & vbCrlf & "}"&vbCrlf & "}"&vbCrlf& _
    "if (j > 0) {"&vbCrlf&_
               "document.form1.select1.options[document.form1.select1.options.length] = new Option(" &  _
              "document.form1.sel2.options[document.form1.sel2.selectedIndex].value,"  & _
              "document.form1.sel2.options[document.form1.sel2.selectedIndex].value);"& vbCrlf
           str=str&"document.form1.sel2.options[document.form1.sel2.selectedIndex] =null;" & vbCrlf &"}"& vbCrlf &"}"& vbCrlf &"}"
    Response.Write "<SCR"& "IPT LANGUAGE=""JavaScript"">" & vbCrlf
    Response.Write str & vbCrlf & "</SCR"&"IPT>"& vbCrlf
    %>
       
     </tr>
  </table>
</form>
</body>
</HTML>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
<!DOCTYPE html> <html> <head> <title>表格形式</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> table, th, td { border: 1px solid black; border-collapse: collapse; padding: 5px; } </style> <script> // 添加一行 function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); for(var i = 0; i < 5; i++){ var cell = row.insertCell(i); cell.innerHTML = '<select><option value="1">选项1</option><option value="2">选项2</option><option value="3">选项3</option></select>'; cell.onclick = function(){ this.firstChild.style.display = 'block'; } cell.firstChild.onblur = function(){ this.style.display = 'none'; } cell.firstChild.style.display = 'none'; } } </script> </head> <body> <table id="myTable"> <thead> <tr> <th>列1</th> <th>列2</th> <th>列3</th> <th>列4</th> <th>列5</th> </tr> </thead> <tbody> <tr> <td><select><option value="1">选项1</option><option value="2">选项2</option><option value="3">选项3</option></select></td> <td><select><option value="1">选项1</option><option value="2">选项2</option><option value="3">选项3</option></select></td> <td><select><option value="1">选项1</option><option value="2">选项2</option><option value="3">选项3</option></select></td> <td><select><option value="1">选项1</option><option value="2">选项2</option><option value="3">选项3</option></select></td> <td><select><option value="1">选项1</option><option value="2">选项2</option><option value="3">选项3</option></select></td> </tr> </tbody> </table> <button onclick="addRow('myTable')">增加</button> </body> </html>将这段代码用bootstrap进行优化
最新发布
04-23
Sure! 这个表格的代码可以用 Bootstrap 进行优化,具体的代码如下: <!DOCTYPE html> <html> <head> <title>表格形式</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 引入 Bootstrap 的 CSS 文件 --> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.5.0/css/bootstrap.min.css"> <style> table { border: 1px solid black; border-collapse: collapse; padding: 5px; } </style> </head> <body> <div class="container"> <table class="table table-bordered table-hover"> <thead> <tr> <th>列1</th> <th>列2</th> <th>列3</th> <th>列4</th> <th>列5</th> </tr> </thead> <tbody> <tr> <td> <select class="form-control"> <option value="1">选项1</option> <option value="2">选项2</option> <option value="3">选项3</option> </select> </td> <td> <select class="form-control"> <option value="1">选项1</option> <option value="2">选项2</option> <option value="3">选项3</option> </select> </td> <td> <select class="form-control"> <option value="1">选项1</option> <option value="2">选项2</option> <option value="3">选项3</option> </select> </td> <td> <select class="form-control"> <option value="1">选项1</option> <option value="2">选项2</option> <option value="3">选项3</option> </select> </td> <td> <select class="form-control"> <option value="1">选项1</option> <option value="2">选项2</option> <option value="3">选项3</option> </select> </td> </tr> </tbody> </table> <div class="text-center"> <button class="btn btn-primary" onClick="addRow('myTable')">增加</button> </div> </div> <!-- 引入 Bootstrap 的 JS 文件 --> <script src="https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.16.0/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script> <script> // 添加一行 function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); for(var i = 0; i < 5; i++) { var cell = row.insertCell(i); cell.innerHTML = '<select class="form-control"><option value="1">选项1</option><option value="2">选项2</option><option value="3">选项3</option></select>'; cell.onclick = function(){ this.firstChild.style.display = 'block'; } cell.firstChild.onblur = function(){ this.style.display = 'none'; } cell.firstChild.style.display = 'none'; } } </script> </body> </html> 我希望这个帮助到你!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bihu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值