注册 登录
编程论坛 JavaScript论坛

Javascript 數組的問題!

xunmi_love 发布于 2009-09-16 16:35, 665 次点击
<script type="text/javascript">
    var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
    xmlDoc.async=false
    xmlDoc.load("dbxml.xml")
    function getArr(s,arrValue)
    {
        var arrResult=new Array();
        if(s!="")
        {
            for(var i=0;i<arrValue.length;i++)
            {
                if(arrValue[i].indexOf(s)==0)
                {
                    arrResult.push(arrValue[i]);
                }
            }
        }
        return arrResult;
     }  
   window.onload=function ()
   {
        document.getElementById("ww").style.display="none";
    }
    function g()//取得焦點時執行動作;
    {
         var aa=document.getElementById("Text1").value;
         if(aa=="") return;
        var root=xmlDoc.documentElement
         var le=root.childNodes.length;
         var stra="Please Check here";
         for(var i =0;i<le;i++)
        {
            stra=stra+","+xmlDoc.getElementsByTagName("name")[i].firstChild.data;
        }
        var arr=[stra];
       // document.write(arr);--這裏是兩個數組,爲什麽粗體的數組就不行呢?請各位路過的大蝦指教!
         var arrs=["red","orange","yellow0","yellow1","yellow2","yellow3","violet4","yellow5","yellow6","yellow7","yellow8","yellow9","yellow10","yellow11","yellow12","yellow13","yellow14","black","tan","ivory","navy","aqua","white","purple","pink","gray","silver"];
//      document.write(arrs);
         arr.sort();
         var arrResult=getArr(aa,arrs);
         var ww=document.getElementById("ww");
         ww.options.length=0;
         for(var i=0;i<arrResult.length;i++)
         {
            ww.options.add(new Option(arrResult[i],arrResult[i]));
         }
        document.getElementById("ww").style.display="";
    }   
    function t()//失去焦點時不顯示;
    {
        document.getElementById("ww").style.display="none";
    }
    function x()
   {
        document.getElementById("ww").style.display="";
   }
  function y()//select 取得焦點的時候,不隱藏;
  {
        var sel=document.getElementById("ww");
        var se="";
        for(var i =0;i<sel.options.length; i++)
        {
            if(sel.options[i].selected==true)
            se=sel.options[i].value;
        }
        document.getElementById("Text1").value=se;
        document.getElementById("ww").style.display="none";
  }  
1 回复
#2
soky2009-09-19 19:40
lz想问什么?
1