首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

,js怎么判断select中没有任何值

2013-10-30 
求助,js如何判断select中没有任何值?select idMySelect size10 stylewidth:500px /select里

求助,js如何判断select中没有任何值?

  <select id="MySelect" size="10" style="width:500px" >
  </select>


里面没有<option></option>时,js如何判断?

document.getElementById("Myselect")options.lenth > 0 (这么写程序会报 “缺少对象”) js select
[解决办法]
id大小写没区分

<select id="MySelect" size="10" style="width:500px" >
  </select>
  <script>
  alert(document.getElementById('MySelect').options.length)
  </script>
[解决办法]

[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]
[解决办法]
document.getElementById("MySelect").options.length 

热点排行