欢迎光临
我们一直在努力

绝对是好东西 (select1 <==> select2):

建站超值云服务器,限时71元/月

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

    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>

      很笨吧, 哈哈!
      若那位大虾有更好的方法, 可别忘了给我寄上一份哦。
      e_mail: fz_chenjl@163.net

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 绝对是好东西 (select1 <==> select2):
分享到: 更多 (0)

相关推荐

  • 暂无文章