getelementbyid没有方法

时间:2011-12-13 21:29:23

标签: javascript html getelementbyid

我有一个下拉菜单,我想要的是当下拉变化时显示先前隐藏的<div>。但我不断收到错误:

uncaught typerror:object #<HTML Document> has no method 'getElementByID'

这是代码

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0    Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
    <title>landing3</title>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function showdiv() {
document.getElementByID("DIV1").style.display = "inline-block";
}
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

      <select id="awf_field-28500717" name="custom Country" tabindex="503" onChange="showdiv()">
        <option class="multiChoice" value="United States">United States</option>
        <option class="multiChoice" value="Canada">Canada</option>
        <option class="multiChoice" value="United Kingdom">United Kingdom</option>
        <option class="multiChoice" value="Australia">Australia</option>
        <option selected>Select</option>
      </select>

    <div id="DIV1" name="DIV1" style="display:none;">
    Test
    </div>
</body>
</html>

2 个答案:

答案 0 :(得分:11)

您有getElementByID而实际方法为getElementById

<script type="text/javascript">
  function showdiv() {
    document.getElementById("DIV1").style.display = "inline-block";
   }
</script>

答案 1 :(得分:0)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0    Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       <html xmlns="http://www.w3.org/1999/xhtml">
       <head>
        <title>landing3</title>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    </head>
    <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

          <select id="awf_field-28500717" name="custom Country" tabindex="503" onChange="showdiv()">
            <option class="multiChoice" value="United States">United States</option>
            <option class="multiChoice" value="Canada">Canada</option>
            <option class="multiChoice" value="United Kingdom">United Kingdom</option>
            <option class="multiChoice" value="Australia">Australia</option>
            <option selected>Select</option>
          </select>

        <div id="DIV1" name="DIV1" style="display:none;">
        Test
        </div>
    </body>
<script type="text/javascript">
    function showdiv() {
    document.getElementById("DIV1").style.display = "inline-block";
    }
    </script>
    </html>