Javascript 避免在JSP页面中进行排序 var sortitems=1; 功能移动(fbox、tbox、all) { 对于(变量i=0;i

Javascript 避免在JSP页面中进行排序 var sortitems=1; 功能移动(fbox、tbox、all) { 对于(变量i=0;i,javascript,jsp,Javascript,Jsp,这个移动函数在点击按钮后被调用,然后它将调用排序方法,按照字母顺序进行排序。因此,我们不需要排序,我们需要填充数据,因为它是从左侧框到右侧框,反之亦然,但排序正在发生。请在这里帮忙 var sortitems = 1; function move(fbox, tbox, all) { for ( var i = 0; i < fbox.options.length; i++) { if (!all && fbox.options[i].se

这个移动函数在点击按钮后被调用,然后它将调用排序方法,按照字母顺序进行排序。因此,我们不需要排序,我们需要填充数据,因为它是从左侧框到右侧框,反之亦然,但排序正在发生。请在这里帮忙

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();
}
功能排序(框)
{
var temp_opts=新数组();
var temp=新对象();
对于(变量i=0;i临时选项[y].value)
{
temp=temp_选项[x]。文本;
临时选项[x]。文本=临时选项[y]。文本;
temp_选择[y]。text=temp;
temp=temp_选项[x]。值;
临时选项[x]。值=临时选项[y]。值;
温度选择[y]。值=温度;
}
}
}
对于(变量i=0;i
取决于缓冲盒功能。元素正在从一个长方体移动到另一个长方体。它将用空的空间替换元素,并移动到顶部,对所有元素执行操作。请帮帮我

提前谢谢

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;
        }
    }
函数放大(框)
{
对于(变量i=0;i
也许只有我一个人,但很难看出问题所在

如果只是在move()函数中调用SortD(tbox),那是因为 sortitems在代码顶部右侧设置为1。sortitems的值在其他任何地方都不会更改,因此此条件始终为true,并且始终调用SortD

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);
        }
    }
if (sortitems)
 SortD(tbox);