<select id="MySelect" size="10" style="width:500px" >
  </select>里面没有<option></option>时,js如何判断?document.getElementById("Myselect")options.lenth > 0 (这么写程序会报 “缺少对象”)jsselect

解决方案 »

  1.   

    id大小写没区分<select id="MySelect" size="10" style="width:500px" >
      </select>
      <script>
      alert(document.getElementById('MySelect').options.length)
      </script>
      

  2.   


    [code=javascript]<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){
    alert("长度为:"+$("select option").length);
    })
    </script>
    <select></select>[/code]
      

  3.   

    document.getElementById("MySelect").options.length