<html>
<head>
<script language="javascript"  type="text/javascript">
alert(document.getElementById("member").options.length)
</script>
</head>
<body>
<select id="member">
<option value="1"></option>
</select>
</body>
</html>代码报错alert那一句缺少对象是为什么啊?

解决方案 »

  1.   

    <script language="javascript"  type="text/javascript">
    alert(document.getElementById("member").options.length)   
    //在解析上面这行代码时member的元素还有加载进来
    </script>
      

  2.   

    try:<html>
    <head>
    <title>this is test</title>
    </head>
    <body>
    <select id="member">
    <option value="1"></option>
    </select>
    <script language="javascript"  type="text/javascript">
    alert(document.getElementById("member").options.length);
    </script>
    </body>
    </html>
      

  3.   

    <html>
    <head>
    <script type="text/javascript">
    function test()
    {
    alert(document.getElementById("member").length);
    }</script>
    </head><body>
    <select id="member">
    <option>123</option>
    </select><input type="submit" onclick="test()" value="show" /></body>
    </html>试试
      

  4.   

    window.onload = function(){alert(document.getElementById("member").options.length);}