站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Javascript 专题关于如何动态地在同一页面实现两个 < select > 互传 (s1 <==> s2)

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

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


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

(jaklin )


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

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

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

<%@ Language=VBScript %>

<head>

</head>
<script language="vbscript">

</script>
<body bgcolor="#ffffff">
<form name="form1" action="test01.asp" target="_self">

<textarea id=text01 name=text01></textarea>


<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>




</td>
<%
str="function do_select() {" & vbCrlf & _
"if (document.form1.select1.options.length > 0) {"&vbCrlf&_
"var j=0;"&vbCrlf&_
"for(var i=0;i "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 "" & vbCrlf
Response.Write str & vbCrlf & ""& vbCrlf

%>

<%
str=""
str="function do_select2() {" & vbCrlf & _
"if (document.form1.sel2.options.length > 0) {"&vbCrlf&_
"var j=0;"&vbCrlf&_
"for(var i=0;i "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 "" & vbCrlf
Response.Write str & vbCrlf & ""& vbCrlf
%>

</tr>
</table>
</form>
</body>

</td> </tr> <tr> <td vAlign=top align=left height="100%">
↑返回目录
前一篇: COOKIE欺骗
后一篇: Javascript技术实现真正的网上试听