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

slysmart 2013-10-29 01:25:04
	  <select id="MySelect" size="10" style="width:500px" >
</select>


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

document.getElementById("Myselect")options.lenth > 0 (这么写程序会报 “缺少对象”)
...全文
311 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
slysmart 2013-10-29
  • 打赏
  • 举报
回复
引用 1 楼 showbo 的回复:
id大小写没区分 <select id="MySelect" size="10" style="width:500px" > </select> <script> alert(document.getElementById('MySelect').options.length) </script>
正解,区分大小写了,自己太粗心了,谢谢各位
chen_ya_ping 2013-10-29
  • 打赏
  • 举报
回复
document.getElementById("MySelect").options.length
  • 打赏
  • 举报
回复

[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]
Go 旅城通票 2013-10-29
  • 打赏
  • 举报
回复
id大小写没区分 <select id="MySelect" size="10" style="width:500px" > </select> <script> alert(document.getElementById('MySelect').options.length) </script>

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧