求助,js如何判断select中没有任何值?
<select id="MySelect" size="10" style="width:500px" >
</select>
里面没有<option></option>时,js如何判断?
document.getElementById("Myselect")options.lenth > 0 (这么写程序会报 “缺少对象”)
------解决方案--------------------id大小写没区分
<select id="MySelect" size="10" style="width:500px" >
</select>
<script>
alert(document.getElementById('My
Select').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