2014-02-11 39 views
0
var sortitems = 1; 

function move(fbox, tbox, all) 
{ 
    for (var i = 0; i < fbox.options.length; i++) 
    { 
     if (!all && fbox.options[i].selected && fbox.options[i].value != "") 
     { 
      var no = new Option(); 
      no.value = fbox.options[i].value; 
      no.text = fbox.options[i].text; 
      tbox.options[tbox.options.length] = no; 
      fbox.options[i].value = ""; 
      fbox.options[i].text = ""; 
     } 
     else 
     { 
      if (all && fbox.options[i].value != "") 
      { 
       var no = new Option(); 
       no.value = fbox.options[i].value; 
       no.text = fbox.options[i].text; 
       tbox.options[tbox.options.length] = no; 
       fbox.options[i].value = ""; 
       fbox.options[i].text = ""; 
      } 
     } 
    } 
    BumpUp(fbox); 

    if (sortitems) 
SortD(tbox); 
    checkSelectAll(); 
} 

这个移动函数在点击按钮后被调用,然后它会调用按照字母顺序排序的排序方法。所以我们不需要排序,我们需要填充数据,因为它是从左侧框到右侧框,反之亦然,但排序正在发生。请帮忙在这里。避免在JSP页面中排序

function SortD(box) 
    { 
     var temp_opts = new Array(); 
     var temp = new Object(); 
     for (var i = 0; i < box.options.length; i++) 
     { 
      temp_opts[i] = box.options[i]; 
     } 
     for (var x = 0; x < temp_opts.length - 1; x++) 
     { 
      for (var y = (x + 1); y < temp_opts.length; y++) 
      { 
       if (temp_opts[x].value > temp_opts[y].value) 
       { 
        temp = temp_opts[x].text; 
        temp_opts[x].text = temp_opts[y].text; 
        temp_opts[y].text = temp; 
        temp = temp_opts[x].value; 
        temp_opts[x].value = temp_opts[y].value; 
        temp_opts[y].value = temp; 
       } 
      } 
     } 
     for (var i = 0; i < box.options.length; i++) 
     { 
      box.options[i].value = temp_opts[i].value; 
      box.options[i].text = temp_opts[i].text; 
     } 
    } 

取决于bumpup box功能。元素正在从一个箱子移动到另一个箱子。它将用空白的元素替换元素,并移动到顶部并为所有元素执行操作。请大家帮帮忙我在这里

在此先感谢

function BumpUp(box) 
    { 
     for (var i = 0; i < box.options.length; i++) 
     { 
      if (box.options[i].value == "") 
      { 
       for (var j = i; j < box.options.length - 1; j++) 
       { 
        box.options[j].value = box.options[j + 1].value; 
        box.options[j].text = box.options[j + 1].text; 
       } 
       var ln = i; 
       break; 
      } 
     } 
     if (ln < box.options.length) 
     { 
      box.options.length -= 1; 
      BumpUp(box); 
     } 
    } 

回答

0

也许这只是我,但它是很难看到的问题是在这里。

如果仅仅是SORTD(TBOX)被称为移动()函数内,这是因为 sortitems是正确的代码的顶部设置为1。 分拣项的值永远不会在其他地方更改,因此该条件始终为真,并始终调用SortD

if (sortitems) 
SortD(tbox);