是这个的问题
document.getElementById('showarea').style.display="block"; 
document.getElementById('showarea').innerHTML = tmphtml; 

解决方案 »

  1.   

    你把JS代码放到HTML代码的下面
    或放到window.onload 函数里去.
      

  2.   

    <html>
    <body onload="init();">
    <div id="showarea" style="display:none;"> <input type="hidden" id="areavalue" value="0"> 
    </div> 
    </body>
    <script> 
    function init(){
      areaname="北京 |天津 |江苏"; 
      areaid="1 |2 |3"; 
      areanamearr=areaname.split(" |"); 
      areaidarr=areaid.split(" |"); 
      
      tmphtml=""; 
      tmphtml="地区: <select name='areaselect' onchange=\"javascript:document.getElementById('areavalue').value=this.value;\">"; 
      for(i=0;i <areanamearr.length;i++) 
      { 
      tmphtml=tmphtml+" <option value='"+areaidarr[i]+"'>"+areanamearr[i]+" </option>"; 
      } 
      tmphtml=tmphtml+" <select> <br>"; 
      //alert(tmphtml); 
      document.getElementById('showarea').style.display="block"; 
      document.getElementById('showarea').innerHTML = tmphtml; 
      }
    </script> 
    </html>
      

  3.   

    不好意思发错了,这个可以
    <html>
    <body onload="init();">
    <div id="showarea" style="display:none;"></div> 
    <input type="text" id="areavalue" value="0"> 
    </body>
    </html>
    <script> 
    function init(){
      areaname="北京 |天津 |江苏"; 
      areaid="1 |2 |3"; 
      areanamearr=areaname.split(" |"); 
      areaidarr=areaid.split(" |"); 
      
      tmphtml=""; 
      tmphtml="地区: <select name='areaselect' onchange=\"javascript:document.getElementById('areavalue').value=this.value;\">"; 
      for(i=0;i <areanamearr.length;i++) 
      { 
      tmphtml=tmphtml+" <option value='"+areaidarr[i]+"'>"+areanamearr[i]+" </option>"; 
      } 
      tmphtml=tmphtml+" <select> <br>"; 
      //alert(tmphtml); 
      document.getElementById('showarea').style.display="block"; 
      document.getElementById('showarea').innerHTML = tmphtml; 
      }
    </script> 
      

  4.   

    <div id="showarea" style="display:none;"> <input type="hidden" id="areavalue" value="0"> 
    </div> 
    为什么会这样呢,因为你的input是被DIV成包含了
    当你document.getElementById('showarea').innerHTML = tmphtml; 的时候,input标签就没有了,所有就找不到对象了