是不是选择后,在右边显示的是“我,你”什么的,不是Item 1,Item 2.......
????
????
解决方案 »
- js 设置 table 中列隐藏后 在火狐中 隐藏列还是显示 tr 设置的背景色
- 为什么客户端事件在IE9和兼容模式下会有不一样的表现?
- 正则如何获取url
- 制作下拉导航条时,默认第一项为Buy Now!并连接到http://www.opencube.com/buy_now.asp
- 一个javascript的问题[高分在线等]
- firefox对js使用问题,为什么在浏览器上按上一部按钮后倒上一页js就失效了
- 初学者的一个很郁闷的JavaScript问题关于document.write
- 关于javascript 类的问题
- 请教屏蔽弹出式窗口的问题
- 刚做的一个没有技术含量的网站,请大家YY!。(批评和建议都要!)
- 一个表格的属性------急 在线等
- 请问去除字符串最后3位字符
Item 1,我
Item 3,你
Item 4,他
..........
...........
..........
列表
下面结果中显示的是
Item 1,我;Item 3,你;Item 4,他;........
---------- ---------- -----------
1 2 3
小项“,”相隔,大的“;”相隔
谢谢,答案正确立即揭贴!
QQyard(网络渔夫) 加油1
下面结果中显示的是
Item 1,我;Item 3,你;Item 4,他;........
---------- ---------- -----------
1 2 3
小项“,”相隔,大的“;”相隔
没完成
稍等
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
function addSrcToDestList() {
destList = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len = destList.length;
var string1="";
for(var i = 0; i < srcList.length; i++) {
if ((srcList.options[i] != null) && (srcList.options[i].selected)) {var found = false;
for(var count = 0; count < len; count++) {
if (destList.options[count] != null) {
if (srcList.options[i].text == destList.options[count].text) {
found = true;
break;
}
}
}if (found != true) {no=document.forms[0].select.selectedIndex;
xm2=document.forms[0].select.options[no].value;destList.options[len] = new Option(srcList.options[i].text+","+xm2);
len++;
}
}
}
for(var i = (len-1); i >= 0; i--)
{
string1=destList.options[i].text+";"+string1;
}
window.document.form1.textfield.value=string1;
}function deleteFromDestList() {
var string2="";
var destList = window.document.forms[0].destList;
var len = destList.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
destList.options[i] = null;
len--;
}
}
for(var j = (len-1); j >= 0; j--)
{
string2=string2+destList.options[j].text;
}
window.document.form1.textfield.value=string2;
}
// -->
</SCRIPT>
</head>
<body>
html>
<center>
<table width="402" height="106" align="center" bgcolor="#FFFFCC">
<form method="POST">
<tr>
<td bgcolor="#FFFFCC" width="92"> <select size="6" name="srcList" multiple>
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6 </select> </td>
<td bgcolor="#FFFFCC" width="103" align="center"> <input type="button" value=" 增加到右边 " onClick="javascript:addSrcToDestList()">
<br> <br> <input type="button" value=" 从右边删除 " onclick="javascript:deleteFromDestList();">
</td>
<td bgcolor="#FFFFCC" width="75"> <select size="6" name="destList" multiple>
</select> </td>
<td bgcolor="#FFFFCC" width="112">右边下拉框显示<br> Item 1,我<br>
Item 2,你</td>
</tr>
<tr>
<td bgcolor="#FFFFCC">
<select name="select">
<option value="我" selected>我</option>
<option value="你">你</option>
<option value="他">他</option>
<option value="第三者">第三者</option>
</select></td>
<td bgcolor="#FFFFCC" align="center"> </td>
<td bgcolor="#FFFFCC"> </td>
<td bgcolor="#FFFFCC"> </td>
</tr>
</form>
</table><table width="45%" border="0" align="center" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action="">
<tr>
<td height="21">您的选择结果是
<input name="textfield" type="text" value="Item 1,我;Item 2,你;"></td>
</tr>
<tr>
<td> </td>
</tr>
</form>
</table>
</body>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
function addSrcToDestList() {
destList = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len = destList.length;
var string1="";
for(var i = 0; i < srcList.length; i++) {
if ((srcList.options[i] != null) && (srcList.options[i].selected)) {var found = false;
for(var count = 0; count < len; count++) {
if (destList.options[count] != null) {
if (srcList.options[i].text == destList.options[count].text) {
found = true;
break;
}
}
}if (found != true) {no=document.forms[0].select.selectedIndex;
xm2=document.forms[0].select.options[no].value;destList.options[len] = new Option(srcList.options[i].text+","+xm2);
len++;
}
}
}
for(var i = (len-1); i >= 0; i--)
{
string1=destList.options[i].text+";"+string1;
}
window.document.form1.textfield.value=string1;
}function deleteFromDestList() {
var string2="";
var destList = window.document.forms[0].destList;
var len = destList.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
destList.options[i] = null;
len--;
}
}
for(var j = (len-1); j >= 0; j--)
{
string2=string2+destList.options[j].text;
}
window.document.form1.textfield.value=string2;
}
// -->
</SCRIPT>
</head>
<body>
html>
<center>
<table width="402" height="106" align="center" bgcolor="#FFFFCC">
<form method="POST">
<tr>
<td bgcolor="#FFFFCC" width="92"> <select size="6" name="srcList" multiple>
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6 </select> </td>
<td bgcolor="#FFFFCC" width="103" align="center"> <input type="button" value=" 增加到右边 " onClick="javascript:addSrcToDestList()">
<br> <br> <input type="button" value=" 从右边删除 " onclick="javascript:deleteFromDestList();">
</td>
<td bgcolor="#FFFFCC" width="75"> <select size="6" name="destList" multiple>
</select> </td>
<td bgcolor="#FFFFCC" width="112">右边下拉框显示<br> Item 1,我<br>
Item 2,你</td>
</tr>
<tr>
<td bgcolor="#FFFFCC">
<select name="select">
<option value="我" selected>我</option>
<option value="你">你</option>
<option value="他">他</option>
<option value="第三者">第三者</option>
</select></td>
<td bgcolor="#FFFFCC" align="center"> </td>
<td bgcolor="#FFFFCC"> </td>
<td bgcolor="#FFFFCC"> </td>
</tr>
</form>
</table><table width="45%" border="0" align="center" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action="">
<tr>
<td height="21">您的选择结果是
<input name="textfield" type="text" value="Item 1,我;Item 2,你;"></td>
</tr>
<tr>
<td> </td>
</tr>
</form>
</table>
</body>
急着下班
改一下
for(var j = (len-1); j >= 0; j--)
{
string2=destList.options[j].text+";"+string2;
}
应该可以
:)
<table border=0 cellpadding=0 cellspacing=0><form name=form>
<tr><td>
<select id=list1 size=8 ondblclick="moveOption(this, this.form.list2)" style="width:100">
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6
</select>
</td>
<td width=40 align=center>
<input name=add type=button value=">>>" onclick="moveOption(this.form.list1, this.form.list2)"><br><br>
<input name=sub type=button value="del" onclick="removeSelect(this.form.list2)">
</td><td>
<select id=list2 size=8 ondblclick="moveOption(this, this.form.list1)" style="width:100">
</select>
</td></tr>
<tr><td colspan="3">
<select name="select3">
<option value="1" selected>我</option>
<option value="2">你</option>
<option value="3">他</option>
<option value="4">第三者</option>
</select><input type="text" name="t1" style="width:200"></td></tr>
</form>
</table><script language="JavaScript"><!--
function moveOption(e1, e2)
{
try
{
var e = e1.options[e1.selectedIndex];
var sel = document.all.select3.options[document.all.select3.selectedIndex].text;
var text = e.text+","+sel;
e2.options.add(new Option(text,e.value));
getValue();
}
catch(e){}
}function removeSelect(e1)
{
try
{
e1.options.remove(e1.selectedIndex);
getValue();
}
catch(e){}
}function getValue()
{
var str="";
for(var i=0;i<document.all.list2.length;i++)
{
str += document.all.list2[i].text+";";
}
str = str.substring(0,str.length-1);
document.form.t1.value = str;
}
//--></script></body>
还有一些遗憾:
1.原来的左选右 是右边若有则添加无效,但是你的可以无限添加,是个小错误吆!
2.结果显示: Item 1,我;Item 3,你;Item 4,他;
最后的分号不要丢失呀!
3.这个是外加的,希望老兄一块做了,可能比这个复杂些,帖子我再加分:
编辑的时候点“编辑”,能否让右边的下拉框显示数据库中的内容,但是仍可以进行先前的操作(在原来的基础上进行增删改)???
谢谢郁忧的曼陀萝,你真是高手呀,不愧为星级高手1一定帮忙呀?
QQyard(网络渔夫)的我正在测试!
<body bgcolor="#FFFFFF">
<table border=0 cellpadding=0 cellspacing=0><form name=form>
<tr><td>
<select id=list1 size=8 ondblclick="moveOption(this, this.form.list2)" style="width:200">
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6
</select>
</td>
<td width=40 align=center>
<input name=add type=button value=">>>" onclick="moveOption(this.form.list1, this.form.list2)"><br><br>
<input name=sub type=button value="del" onclick="moveOption(this.form.list2,this.form.list1)">
</td><td>
<select id=list2 size=8 ondblclick="moveOption(this, this.form.list1)" style="width:200">
</select>
</td></tr>
<tr><td colspan="3">
<select name="select3">
<option value="1" selected>我</option>
<option value="2">你</option>
<option value="3">他</option>
<option value="4">第三者</option>
</select><input type="text" name="t1" style="width:300"><button onclick="edit()">编辑</button></td></tr>
</form>
</table><script language="JavaScript"><!--
var arr = new Array("Items1","Items2","Items3","Items4","Items5","Items6","Items7","Items8","Items9","Items10");
var sel = document.all.list2;
function moveOption(e1, e2)
{
try
{
var text = "";
var e = e1.options[e1.selectedIndex];
var sel = document.all.select3.options[document.all.select3.selectedIndex].text;
if(e1.id == "list1")
{
text = e.text+","+sel;
}
else
{
text = e.text.split(",")[0];
}
e2.options.add(new Option(text,e.value));
e1.options.remove(e1.selectedIndex);
getValue();
}
catch(e){}
}
function getValue()
{
var str="";
for(var i=0;i<sel.length;i++)
{
str += document.all.list2[i].text+";";
}
document.form.t1.value = str;
}
function edit()
{
for(var i=0;i<arr.length;i++)
{
sel.options.add(new Option(arr[i],arr[i]))
}
}
//-->
</script>
</body>
其实这个问题已经解决了一半,
我的想法是这样的:
为了操作起来更加方便,我觉得是否将将添加页面和编辑页面分开来做,添加的就是你上边程序实现的:一)添加的基本完成,我还有一些小的需求,在>
<input type="text" name="t1" style="width:300">后加一个
<input type="hidden" name="t2" style="width:300">主要显示选种项的value值,
例如:1,2;3,1;4,1;5,2二)编辑中我想要的效果是:
1.右边可以回到左边,左边也可以加到右边
2.t1字段也随着变化,
3.下面的代码你看一下
<body bgcolor="#FFFFFF">
<table border=0 cellpadding=0 cellspacing=0><form name=form>
<tr><td>
<select id=list1 size=8 ondblclick="moveOption(this, this.form.list2)" style="width:200">
<option value="1">Item 1
<option value="5">Item 5
<option value="6">Item 6
</select>
</td>
<td width=40 align=center>
<input name=add type=button value=">>>" onclick="moveOption(this.form.list1, this.form.list2)"><br><br>
<input name=sub type=button value="del" onclick="moveOption(this.form.list2,this.form.list1)">
</td><td>
<select id=list2 size=8 ondblclick="moveOption(this, this.form.list1)" style="width:200">
<option value="2">Item 2,我
<option value="3">Item 3,他
<option value="4">Item 4,第三者
</select>
</td></tr>
<tr><td colspan="3">
<select name="select3">
<option value="1" selected>我</option>
<option value="2">你</option>
<option value="3">他</option>
<option value="4">第三者</option>
</select><input type="text" name="t1" style="width:300"><button onclick="edit()">编辑</button></td></tr>
</form>
</table><script language="JavaScript"><!--
var arr = new Array("Items1","Items2","Items3","Items4","Items5","Items6","Items7","Items8","Items9","Items10");
var sel = document.all.list2;
function moveOption(e1, e2)
{
try
{
var text = "";
var e = e1.options[e1.selectedIndex];
var sel = document.all.select3.options[document.all.select3.selectedIndex].text;
if(e1.id == "list1")
{
text = e.text+","+sel;
}
else
{
text = e.text.split(",")[0];
}
e2.options.add(new Option(text,e.value));
e1.options.remove(e1.selectedIndex);
getValue();
}
catch(e){}
}
function getValue()
{
var str="";
for(var i=0;i<sel.length;i++)
{
str += document.all.list2[i].text+";";
}
document.form.t1.value = str;
}
function edit()
{
for(var i=0;i<arr.length;i++)
{
sel.options.add(new Option(arr[i],arr[i]))
}
}
//-->
</script>
</body> 出现的问题是:
1.右边的选回去后再向坐选,出现问题了
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
function addSrcToDestList() {
destList = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len1 = destList.length;
var len2 = srcList.length;
var string1="";
for(var i = 0; i < len2; i++) {
if ((srcList.options[i] != null) && (srcList.options[i].selected)) {var found = false;
for(var count = 0; count < len1; count++) {
if (destList.options[count] != null) {
if (srcList.options[i].text == destList.options[count].text) {
found = true;
break;
}
}
}if (found != true) {no=document.forms[0].select.selectedIndex;
xm2=document.forms[0].select.options[no].value;destList.options[len1] = new Option(srcList.options[i].text+","+xm2);
len1++;
}
}
}
for(var k = (len2-1); k >= 0; k--) {
if ((srcList.options[k] != null) && (srcList.options[k].selected == true)) {
srcList.options[k] = null;
len2--;
}
}
for(var i = (len1-1); i >= 0; i--)
{
string1=destList.options[i].text+";"+string1;
}
window.document.form1.textfield.value=string1;
}function deleteFromDestList() {
var string2="";
var destList = window.document.forms[0].destList;
var len1 = destList.options.length;
var len2 = srcList.options.length;
for(var i = (len1-1); i >= 0; i--) {
if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
found = true;
break;
}
}
if (found == true) {
item1=destList.options[i].text.split(",");
srcList.options[len2] = new Option(item1[0]);
destList.options[i] = null;
len2++;
len1--;
}for(var j = (len1-1); j >= 0; j--)
{
string2=destList.options[j].text+";"+string2;
}
window.document.form1.textfield.value=string2;
}
// -->
</SCRIPT>
</head>
<body>
html>
<center>
<table width="402" height="106" align="center" bgcolor="#FFFFCC">
<form method="POST">
<tr>
<td bgcolor="#FFFFCC" width="92"> <select size="6" name="srcList" multiple>
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6 </select> </td>
<td bgcolor="#FFFFCC" width="103" align="center"> <input type="button" value=" 增加到右边 " onClick="javascript:addSrcToDestList()">
<br> <br> <input type="button" value=" 从右边删除 " onclick="javascript:deleteFromDestList();">
</td>
<td bgcolor="#FFFFCC" width="75"> <select size="6" name="destList" multiple>
</select> </td>
<td bgcolor="#FFFFCC" width="112">右边下拉框显示<br> Item 1,我<br>
Item 2,你</td>
</tr>
<tr>
<td bgcolor="#FFFFCC">
<select name="select">
<option value="我" selected>我</option>
<option value="你">你</option>
<option value="他">他</option>
<option value="第三者">第三者</option>
</select></td>
<td bgcolor="#FFFFCC" align="center"> </td>
<td bgcolor="#FFFFCC"> </td>
<td bgcolor="#FFFFCC"> </td>
</tr>
</form>
</table><table width="45%" border="0" align="center" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action="">
<tr>
<td height="21">您的选择结果是
<input name="textfield" type="text" value="Item 1,我;Item 2,你;"></td>
</tr>
<tr>
<td> </td>
</tr>
</form>
</table>
</body>
<input type="text" name="t1" style="width:300">后加一个
<input type="hidden" name="t2" style="width:300">主要显示选种项的value值,
例如:1,2;3,4;二)编辑页面
表结构如下:
表一:
表明 tname
字段 ID(num) t2(vchar2)
1 1,2;3,4;(我么选择的结果)
表二:
HID(num) ttt(vchar2)
1 Item 1
2 Item 2
3 Item 3
4 Item 4
5 Item 5
6 Item 6
二)编辑中我想要的效果是:
1.右边的是选中的记录,左边的是选剩下几条记录
2.左右可以互选
3.t1、t2值跟随变化!
看一下<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
var arr = new Array("我","你","他","第三者");function addSrcToDestList() {
destList = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len1 = destList.length;
var len2 = srcList.length;
var string1="";
var string2="";
for(var i = 0; i < len2; i++) {
if ((srcList.options[i] != null) && (srcList.options[i].selected)) {var found = false;
for(var count = 0; count < len1; count++) {
if (destList.options[count] != null) {
if (srcList.options[i].text == destList.options[count].text) {
found = true;
break;
}
}
}if (found != true) {no=document.forms[0].select.selectedIndex;
xm2=document.forms[0].select.options[no].value;destList.options[len1] = new Option(srcList.options[i].text+","+arr[xm2-1]);
len1++;
}
}
}
for(var k = (len2-1); k >= 0; k--) {
if ((srcList.options[k] != null) && (srcList.options[k].selected == true)) {
srcList.options[k] = null;
len2--;
}
}
for(var i = (len1-1); i >= 0; i--)
{
item1=destList.options[i].text.split(",");
string1=item1[0]+";"+string1;
for(m=0;m<=3;m++)
if(item1[1]==arr[m])
break;
m+=1;
string2=m+";"+string2;
}
window.document.form1.textfield.value=string1;
window.document.form1.t1.value=string2;}function deleteFromDestList() {
var string1="";
var string2="";
var destList = window.document.forms[0].destList;
var len1 = destList.options.length;
var len2 = srcList.options.length;
for(var i = (len1-1); i >= 0; i--) {
if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
found = true;
break;
}
}
if (found == true) {
item1=destList.options[i].text.split(",");
srcList.options[len2] = new Option(item1[0]);
destList.options[i] = null;
len2++;
len1--;
}for(var j = (len1-1); j >= 0; j--)
{
item1=destList.options[j].text.split(",");
string1=item1[0]+";"+string1;
for(m=0;m<=3;m++)
if(item1[1]==arr[m])
break;
m+=1;
string2=m+";"+string2;
}
window.document.form1.textfield.value=string1;
window.document.form1.t1.value=string2;}
// -->
</SCRIPT>
</head>
<body><center>
<table width="402" height="106" align="center" bgcolor="#FFFFCC">
<form method="POST">
<tr>
<td bgcolor="#FFFFCC" width="92"> <select size="6" name="srcList" multiple>
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6 </select>一 </td>
<td bgcolor="#FFFFCC" width="103" align="center"> <input type="button" value=" 增加到右边 " onClick="javascript:addSrcToDestList()">
<br> <br> <input type="button" value=" 从右边删除 " onclick="javascript:deleteFromDestList();">
</td>
<td bgcolor="#FFFFCC" width="75"> <select size="6" name="destList" multiple>
</select> </td>
</tr>
<tr>
<td bgcolor="#FFFFCC">
<select name="select">
<option value="1" selected>我</option>
<option value="2">你</option>
<option value="3">他</option>
<option value="4">第三者</option>
</select>二</td>
<td bgcolor="#FFFFCC" align="center"> </td>
<td bgcolor="#FFFFCC"> </td>
</tr>
</form>
</table><table width="45%" border="0" align="center" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action="">
<tr>
<td height="21">一的选择结果是
<input name="textfield" type="text" size="20"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td height="21">二的选择结果是
<input name="t1" type="text" size="20"></td>
</tr>
</form>
</table>
</body>
<html>
<head>
</head>
<body bgcolor="#FFFFFF">
<form name="form1">
<table border=0 cellpadding=0 cellspacing=0><form name=form>
<tr>
<td>
<select id=list1 size=8 ondblclick="moveOption(this, this.form.list2)" style="width:200">
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6
</select>
</td>
<td width=40 align=center>
<input name=add type=button value=">>>" onclick="moveOption(this.form.list1, this.form.list2)"><br/><br/>
</td>
<td>
<select id=list2 size=8 ondblclick="moveOption(this, this.form.list1)" style="width:200">
</select>
</td>
</tr>
<tr>
<td colspan="3">
<select name="select3">
<option value="1" selected>我</option>
<option value="2">你</option>
<option value="3">他</option>
<option value="4">第三者</option>
</select>
<button onclick="edit()">编辑</button>
</td>
</tr>
</table>
</form>
<script language="JavaScript"><!--
var arr = new Array("Items1","Items2","Items3","Items4","Items5","Items6","Items7","Items8","Items9","Items10");
var sel = document.all.list2;
function moveOption(e1, e2)
{
try
{
var text = "";
var e = e1.options[e1.selectedIndex];
var sel = document.all.select3.options[document.all.select3.selectedIndex].text;
if(e1.id == "list1")
{
text = e.text+","+sel;
}
else
{
text = e.text.split(",")[0];
}
e2.options.add(new Option(text,e.value));
e1.options.remove(e1.selectedIndex);
getValue();
}
catch(e){}
}
function getValue()
{
var str="";
for(var i=0;i<sel.length;i++)
{
str += document.all.list2[i].text+";";
}
document.form.t1.value = str;
}
function edit()
{
window.open("edit.html")
}
//-->
</script>
</body>
</html>弹出页面代码: 在后面
<html>
<head>
<script language="JavaScript">
<!--
function init()
{
var list1 = opener.document.all.list1;
var list2 = opener.document.all.list2;
if(list1.length>0)
{
putValue(list1,document.all.select1);
}
if(list2.length>0)
{
putValue(list2,document.all.select2);
}
getValue();
}function putValue(list,select)
{
for(var i=0;i<list.length;i++)
{
select.options.add(new Option(list[i].text,list[i].value));
}}
var arr = new Array("Items1","Items2","Items3","Items4","Items5","Items6","Items7","Items8","Items9","Items10");
var sel = document.all.select2;
function moveOption(e1, e2)
{
try
{
var text = "";
var e = e1.options[e1.selectedIndex];
var sel = document.all.select3.options[document.all.select3.selectedIndex].text;
if(e1.id == "select1")
{
text = e.text+","+sel;
}
else
{
text = e.text.split(",")[0];
}
e2.options.add(new Option(text,e.value));
e1.options.remove(e1.selectedIndex);
getValue();
}
catch(e){}
}
function getValue()
{
var str="";
var val="";
for(var i=0;i<document.all.select2.length;i++)
{
str += document.all.select2[i].text+";";
val += document.all.select2[i].value+",";
}
document.all.t1.value = str;
document.all.t2.value = val;
}
function edit()
{
for(var i=0;i<arr.length;i++)
{
document.all.select2.options.add(new Option(arr[i],arr[i]))
}
getValue();
}
//-->
</script>
</head><body bgcolor="#FFFFFF" onload="init()">
<form name="form1">
<table border=0 cellpadding=0 cellspacing=0><form name=form>
<tr>
<td>
<select id=select1 size=8 ondblclick="moveOption(this, this.form.select2)" style="width:200"></select>
</td>
<td width=40 align=center>
<input name=add type=button value=">>>" onclick="moveOption(this.form.select1, this.form.select2)"><br/><br/>
<input name=sub type=button value="del" onclick="moveOption(this.form.select2,this.form.select1)">
</td>
<td>
<select id=select2 size=8 ondblclick="moveOption(this, this.form.select1)" style="width:200"></select>
</td>
</tr>
<tr>
<td colspan="3">
<select name="select3">
<option value="1" selected>我</option>
<option value="2">你</option>
<option value="3">他</option>
<option value="4">第三者</option>
</select>
<input type="text" name="t1" style="width:400">
<input type="hidden" name="t2">
<button onclick="edit()">添加数据库里的内容</button>
<button onclick="alert(document.all.t2.value)">查看隐含字段里的内容</button>
</td>
</tr>
</table>
</form>
</body>
</html>
效果是这样
<input type="text" name="t1" style="width:300"> Item 1,我;Item 2 ,她;
<input type="hidden" name="t2" style="width:300"> 1,1;2,3;
好,改了
<html>
<head>
<script language="JavaScript">
<!--
function init()
{
var list1 = opener.document.all.list1;
var list2 = opener.document.all.list2;
if(list1.length>0)
{
putValue(list1,document.all.select1);
}
if(list2.length>0)
{
putValue(list2,document.all.select2);
}
getValue();
}function putValue(list,select)
{
for(var i=0;i<list.length;i++)
{
select.options.add(new Option(list[i].text,list[i].value));
}}
var arr = new Array("Items1","Items2","Items3","Items4","Items5","Items6","Items7","Items8","Items9","Items10");
var sel = document.all.select2;
function moveOption(e1, e2)
{
try
{
var text = "";
var values = "";
var e = e1.options[e1.selectedIndex];
var sel = document.all.select3.options[document.all.select3.selectedIndex].text;
var theV = document.all.select3.options[document.all.select3.selectedIndex].value;
if(e1.id == "select1")
{
text = e.text+","+sel;
values = e.value+","+theV;
}
else
{
text = e.text.split(",")[0];
values = e.value.split(",")[0];
}
e2.options.add(new Option(text,values));
e1.options.remove(e1.selectedIndex);
getValue();
}
catch(e){}
}
function getValue()
{
var str="";
var val="";
for(var i=0;i<document.all.select2.length;i++)
{
str += document.all.select2[i].text+";";
val += document.all.select2[i].value+";";
}
document.all.t1.value = str;
document.all.t2.value = val;
}
function edit()
{
for(var i=0;i<arr.length;i++)
{
document.all.select2.options.add(new Option(arr[i],arr[i]))
}
getValue();
}
//-->
</script>
</head><body bgcolor="#FFFFFF" onload="init()">
<form name="form1">
<table border=0 cellpadding=0 cellspacing=0><form name=form>
<tr>
<td>
<select id=select1 size=8 ondblclick="moveOption(this, this.form.select2)" style="width:200"></select>
</td>
<td width=40 align=center>
<input name=add type=button value=">>>" onclick="moveOption(this.form.select1, this.form.select2)"><br/><br/>
<input name=sub type=button value="del" onclick="moveOption(this.form.select2,this.form.select1)">
</td>
<td>
<select id=select2 size=8 ondblclick="moveOption(this, this.form.select1)" style="width:200"></select>
</td>
</tr>
<tr>
<td colspan="3">
<select name="select3">
<option value="1" selected>我</option>
<option value="2">你</option>
<option value="3">他</option>
<option value="4">第三者</option>
</select>
<input type="text" name="t1" style="width:400">
<input type="hidden" name="t2">
<button onclick="edit()">添加数据库里的内容</button>
<button onclick="alert(document.all.t2.value)">查看隐含字段里的内容</button>
</td>
</tr>
</table>
</form>
</body>
</html>
尤其感谢kisslan(郁忧的曼陀萝)!!!
<html>
<head>
</head>
<body bgcolor="#FFFFFF">
<form name="form1">
<table border=0 cellpadding=0 cellspacing=0><form name=form>
<tr>
<td>
<select id=list1 size=8 ondblclick="moveOption(this, this.form.list2)" style="width:200">
<option value="1">Item 1
<option value="2">Item 2
<option value="3">Item 3
<option value="4">Item 4
<option value="5">Item 5
<option value="6">Item 6
</select>
</td>
<td width=40 align=center>
<input name=add type=button value=">>>" onclick="moveOption(this.form.list1, this.form.list2)"><br/><br/>
</td>
<td>
<select id=list2 size=8 ondblclick="moveOption(this, this.form.list1)" style="width:200">
</select>
</td>
</tr>
<tr>
<td colspan="3">
<select name="select3">
<option value="1" selected>我</option>
<option value="2">你</option>
<option value="3">他</option>
<option value="4">第三者</option>
</select>
<button onclick="edit()">编辑</button>
</td>
</tr>
</table>
</form>
<script language="JavaScript"><!--
var sel = document.all.list2;
function moveOption(e1, e2)
{
try
{
var text = "";
var values = "";
var e = e1.options[e1.selectedIndex];
var sel = document.all.select3.options[document.all.select3.selectedIndex].text;
var theV = document.all.select3.options[document.all.select3.selectedIndex].value;
if(e1.id == "list1")
{
text = e.text+","+sel;
values = e.value+","+theV;
}
else
{
text = e.text.split(",")[0];
values = e.value.split(",")[0];
}
e2.options.add(new Option(text,values));
e1.options.remove(e1.selectedIndex);
getValue();
}
catch(e){}
}function edit()
{
window.open("edit.html")
}
//-->
</script>
</body>
</html>