我用js做了一个功能:
在一个表单中共有三个按钮和两个(左,右)可多选的select项,点第一个按钮让数据从左边的select项中移到右边。第二个相反。第三个是表单提交。我执行了数据从左边移到了右边。而且左边消失了,右边增加了。可是提交表单时,数据还是最初的数据(移动前的数据),
为什么,麻烦哪位高手帮忙看看。代码如下:js代码:
               // 提交表单用
               function deviceManagerApply(path){

  document.deviceManagerForm.action=path;
  document.deviceManagerForm.submit();
}

         //向左面添加选项
function mvToLeftLine(lobj, robj){
         var selectLines = document.getElementById("inGrpDevice");
var lLine = document.getElementById("unGrpDevice");

for(var i = 0; i < selectLines.length; i++){
if (selectLines.options[i].selected){
// 向左面添加选项
var opt = new Option(selectLines.options[i].value, selectLines.options[i].value);
//var opt = new Option(selectLines.options[i].value, lLine.length + i);
lobj.options.add(opt);
}
}
for(var j = selectLines.length -1; 0 <= j; j--){
if(selectLines.options[j].selected){
// 从右面删除选项
selectLines.options.remove(j);
}
}
}
// 向右边添加选项
function mvToRightLine(lobj, robj){
var selectLines = document.getElementById("unGrpDevice");
var rLine = document.getElementById("inGrpDevice");
for (var i = 0; i < selectLines.length; i++){
if (selectLines.options[i].selected){
// 向右面添加选项
var opt = new Option(selectLines.options[i].value, selectLines.options[i].value);
//var opt = new Option(selectLines.options[i].value, rLine.length+i);
robj.options.add(opt);

}
}

for (var j = selectLines.length -1; 0 <= j; j--){
if (selectLines.options[j].selected){

// 从左面删除选项
selectLines.options.remove(j);
}
}
}表单代码:
<form name="deviceManagerForm">
<s:select list="unGrpDevice" name="unGrpDevice" id="unGrpDevice" size="30" multiple="true" style="width:300px" ></s:select>
<input type="button" name="toRight" value="-->>" onclick="mvToRightLine(unGrpDevice, inGrpDevice)" />
<input type="button" name="toLeft" value="<<--" onclick="mvToLeftLine(unGrpDevice, inGrpDevice)"/>
<input type="button" name="apply" value="应用" onclick="deviceManagerApply('Group/deviceGroupManager')"/>
<s:select list="inGrpDevice" size="30" multiple="true" name="inGrpDevice" id="inGrpDevice" style="width:300px">
</form>

解决方案 »

  1.   

    你的左边移到了右边,只是把option移动,select的值没有改变,试下function deviceManagerApply(path){
      document.deviceManagerForm.action=path;
      var rLine = document.getElementById("inGrpDevice");
      for (var i = 0; i < rLine.length; i++)rLine.options[i].selected=true;
      document.deviceManagerForm.submit();
    }