問一個select多選框的問題﹗ 实在不行就只好上传个字符串了定义一个hidden的input,存放select里所有option的value值连成的字符串,到了需要的地方再解析 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script language="javascript"> var products_function = document.all.products_function.options;var len = document.all.products_function.options.length;for (var i=0;i<len;i++) { if(document.all.products_function.options[0].text=="") document.all.products_function.options.remove(0); else products_function = document.all.products_function.options[i].concat(',');}</script> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><SCRIPT LANGUAGE="JavaScript"><!-- function addItem(source,target,maxItem,allowRepeat){if(!allowRepeat)allowRepeat = false;if(!source || !target || source.tagName!='SELECT' || target.tagName!='SELECT') return false;for(var i=0; i<source.options.length;i++){if(source.options[i].selected){if(!allowRepeat && findItem(target,source.options[i].text,source.options[i].value,1)!=null)alert("\"" + source.options[i].text + "\"" + "已經存在!");elsetarget.options.add(new Option(source.options[i].text,source.options[i].value));}}}function delItem(source){if(!source || source.tagName!='SELECT') return false;for(var i=source.options.length-1; i>=0; i--){if(source.options[i].selected) source.options.remove(i);}}function findItem(target,text,value,flag){if(!flag) flag = 0;if(!target || target.tagName!='SELECT') return null;for(var i=0;i<target.options.length;i++){if(flag==1 && target.options[i].value==value) return target.options[i];if(flag==2 && target.options[i].text==text)return target.options[i];if(target.options[i].text==text&&target.options[i].value==value) return target.options[i];}return null;}function selectAll(){var obj = document.getElementById("products_function");for (var i=0; i<obj.options.length; i++){obj.options[i].selected = true;}}//--></SCRIPT></HEAD><BODY><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr><td width="10%" valign="top"><select name="products_function1" size="5" style="width:12em" multiple id="products_function1" ondblclick="addItem(this,document.all.products_function)"><option value="1">防雨</option><option value="2">防震</option></select> </td><script language="javascript"> if(document.all.products_function1.options[0].text=="") document.all.products_function1.options.remove(0); </script> <td width="10%" align="center"><input type="button" name="enter" value="=>" onclick="addItem(document.all.products_function1,document.all.products_function)"><br><input type="button" name="remove" value="<=" onclick="delItem(document.all.products_function)"></td><td width="20%"><select name="products_function" size="5" style="width:12em" multiple id="products_function" ondblclick="delItem(this)"><option value="" SELECTED></option></select></td><script language="javascript">if(document.all.products_function.options[0].text=="") document.all.products_function.options.remove(0); </script><td><input type="submit" value="submit" onclick="selectAll();return abc()"></td> </tr></table><div id="div1"></div></BODY></HTML><script language="javascript"> function abc(){ var products_function = document.all.products_function.options; var len = document.all.products_function.options.length; for (var i=0;i<len;i++) { if(document.all.products_function.options[0].text=="") document.all.products_function.options.remove(0); else document.getElementById("div1").innerHTML += "選択項 番号" + i + ": " + " value = " + document.all.products_function.options[i].value + " text = " + document.all.products_function.options[i].innerText + " <br> " ; } return false;}</script> Jquery ajax JSON 返回数组问题。。 请帮我完成javascript的作业啊,多谢各位啦。 高分求教shadowbox js调用方法。SOS 下面这段Javascript为什么不能在FireFox中正常执行 一个js的语法糖 关于options.selectedIndex的疑问,谢谢。 请问, javascript 有没有Enumerator? 贪吃蛇(二) 远程服务器文件压缩下载 flash点击播放能不能加自己的事件处理 如何禁止选择页面上的东西,但是允许选择输入框中的内容 img图像的鼠标拖动平移如何实现?
var products_function = document.all.products_function.options;
var len = document.all.products_function.options.length;
for (var i=0;i<len;i++)
{
if(document.all.products_function.options[0].text=="")
document.all.products_function.options.remove(0);
else
products_function = document.all.products_function.options[i].concat(',');
}
</script>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- function addItem(source,target,maxItem,allowRepeat)
{
if(!allowRepeat)allowRepeat = false;
if(!source || !target || source.tagName!='SELECT' || target.tagName!='SELECT') return false;for(var i=0; i<source.options.length;i++)
{
if(source.options[i].selected)
{
if(!allowRepeat && findItem(target,source.options[i].text,source.options[i].value,1)!=null)
alert("\"" + source.options[i].text + "\"" + "已經存在!");
else
target.options.add(new Option(source.options[i].text,source.options[i].value));
}
}
}
function delItem(source)
{
if(!source || source.tagName!='SELECT') return false;
for(var i=source.options.length-1; i>=0; i--)
{
if(source.options[i].selected) source.options.remove(i);
}
}function findItem(target,text,value,flag)
{
if(!flag) flag = 0;
if(!target || target.tagName!='SELECT') return null;
for(var i=0;i<target.options.length;i++)
{
if(flag==1 && target.options[i].value==value)
return target.options[i];
if(flag==2 && target.options[i].text==text)
return target.options[i];
if(target.options[i].text==text&&target.options[i].value==value)
return target.options[i];
}
return null;
}function selectAll()
{
var obj = document.getElementById("products_function");
for (var i=0; i<obj.options.length; i++)
{
obj.options[i].selected = true;
}}
//-->
</SCRIPT>
</HEAD><BODY>
<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr>
<td width="10%" valign="top">
<select name="products_function1" size="5" style="width:12em" multiple id="products_function1" ondblclick="addItem(this,document.all.products_function)">
<option value="1">防雨</option>
<option value="2">防震</option></select>
</td>
<script language="javascript"> if(document.all.products_function1.options[0].text=="") document.all.products_function1.options.remove(0); </script> <td width="10%" align="center"><input type="button" name="enter" value="=>" onclick="addItem(document.all.products_function1,document.all.products_function)"><br>
<input type="button" name="remove" value="<=" onclick="delItem(document.all.products_function)">
</td>
<td width="20%">
<select name="products_function" size="5" style="width:12em" multiple id="products_function" ondblclick="delItem(this)">
<option value="" SELECTED></option></select>
</td>
<script language="javascript">
if(document.all.products_function.options[0].text=="") document.all.products_function.options.remove(0); </script>
<td><input type="submit" value="submit" onclick="selectAll();return abc()"></td> </tr>
</table>
<div id="div1"></div>
</BODY>
</HTML>
<script language="javascript">
function abc(){
var products_function = document.all.products_function.options;
var len = document.all.products_function.options.length;
for (var i=0;i<len;i++)
{
if(document.all.products_function.options[0].text=="")
document.all.products_function.options.remove(0);
else
document.getElementById("div1").innerHTML += "選択項 番号" + i + ": "
+ " value = " + document.all.products_function.options[i].value
+ " text = " + document.all.products_function.options[i].innerText
+ " <br> " ;
}
return false;
}
</script>