js代码问题,求大神解答。。初学js。。老师布置的作业。

2025-04-29 07:36:24
推荐回答(2个)
回答1:





recursion



var text = function ()
    {
    var os = textOne.children, ts = textTwo.children;
    for ( var i = 0; i < os.length; i++)
    {
    var osi = os[i];
    if (osi.selected)
    {
     for ( var j = 0; j < ts.length; j++)
                {
                if (ts[j].value == osi.value)
                    {
                    alert("已经存在 " + osi.innerHTML);
                    return;
                    }
                }
    var opt = document.createElement ('option');
    opt.value = osi.value;
    opt.innerHTML = osi.innerHTML;
    textTwo.appendChild (opt);
    break;
    }
    }
    }




菜单一
菜单二
菜单三

>>



回答2:

function text(){
    var textOne=document.getElementById("textOne");
    var textTwo=document.getElementById("textTwo");
    var optin=document.createElement("option");
    var flag=true;
    for(var i=0;i        if(textOne.options[i].selected){
           for(var j=0;j               if(textTwo.options[i].innerHTML==textOne.options[i].innerHTML){
                   flag=false;
                   break;
                }
            } 
            if(flag){
                optin=document.createElement("option");
                optin.innerHTML=textOne.options[i].innerHTML;
                textTwo.appendChild(optin);
            }
        }
    }