日期:2014-05-16  浏览次数:20504 次

关于列表框按选择顺序取值的问题
各位下午好!

我有一个问题想请教:

有一个列表框如下:

<select   id= "aaa "   multiple     onchange= "mSelect() ">
<option   value   = "1 "> A </option>
<option   value   = "2 "> B </option>
<option   value   = "3 "> C </option>
<option   value   = "4 "> D </option>
<option   value   = "5 "> E </option>
<option   value   = "6 "> F </option>
<option   value   = "7 "> G </option>
<option   value   = "8 "> H </option>
</select>

如果我依次选中   G-D-F-A-B
我想得到的value值是74612,那么javascript:mSelect()   如何写?




------解决方案--------------------
<form name=form1 >
<select id= "aaa " name= "aaa " multiple onchange= "Selected(this) ">
<option value = "1 "> A </option>
<option value = "2 "> B </option>
<option value = "3 "> C </option>
<option value = "4 "> D </option>
<option value = "5 "> E </option>
<option value = "6 "> F </option>
<option value = "7 "> G </option>
<option value = "8 "> H </option>
<option value = "9 "> I </option>
<option value = "10 "> J </option>
<option value = "11 "> K </option>
</select>
<input type= "button " value= "按钮 " name= "B3 " onclick = "mSelect() "> <input type= "text " name= "ccc " size= "20 "> </form>
<textarea rows= "20 " name= "bbb " cols= "10 "> </textarea>
<script language=javascript>
var temparr = new Array();
var tempstr = " ";
var tempstr1 = " ";
var tempstr2 = " ";
function Selected(obj)
{
for(var i=0;i <obj.options.length;i++)
{
var oOption = obj.options[i];
var tempvalue = "| "+oOption.value+ "| ";
if(tempstr.indexOf(tempvalue)==-1 && oOption.selected)tempstr += tempvalue;
if(tempstr.indexOf(tempvalue)> -1 && !oOption.selected)tempstr = tempstr.replace(tempvalue, " ");
}
temparr = tempstr.replace(/(?:\|$|^\|)/g, " ").split( "|| ");
}

function mSelect()
{
document.getElementById( "bbb ").value= temparr.join( " ");
document.getElementById( "ccc ").value= temparr.join( "\n ");
}
</script>