读书人

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

发布时间: 2013-10-30 12:56:22 作者: rapoo

求助,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

读书人网 >JavaScript

热点推荐