首页  »   JavaScript

关于列表框按选择顺序取值的有关问题

网友分享于:2013-02-22  浏览:6次
关于列表框按选择顺序取值的问题
各位下午好!

我有一个问题想请教:

有一个列表框如下:

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

相关解决方案

最新解决方案