getElementById 能取几个select的length吗 最简单的办法就把三个id取成不同的值.分别取length; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没明白楼上老大的意思???我是想得到有几个select. var flag=0;var allSelect=document.getElementsByTagName("select");for(var i=0;i<allSelect.length;i++){ if(allSelect[i].id=="select_user_id") flag++;}alert(flag); 当然. 最好的方法 还是用name属性那 getElementsByName 就能得到了 <html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title> <script type="text/javascript"> function FindSpan() { document.writeln(document.getElementsByName("select_user_id").length); }</script></head><body><select multiple size=10 id="select_user_id" name="select_user_id"><option value="1"> 1 </option><option value="2"> 2 </option></select><select multiple size=10 id="select_user_id" name="select_user_id"><option value="a"> a </option><option value="b"> b </option></select><select multiple size=10 id="select_user_id" name="select_user_id"><option value="q"> q </option><option value="f"> f </option></select><button value="Click me" onclick="FindSpan()"></button></body></html> 写一个JS类, 可以一次生成如下的这样的相册 新浪微博点下一页改变了url但只局部刷新怎么做的 js控制div的高 求点javascript资料 一个灰常灰常简单的js问题-动态设置文本框的属性 页面输出字数限制用js控制时的换行问题 怎样在firefox中判断浏览器是关闭还是刷新 散100分请解决动态table的效率问题 如何让另存为的窗口的保存类型默认为*.xls的? 高分求教javascript菜问题 要怎样才能知道层的内容有没有溢出呢? js里中文在firefox console里显示乱码?
var allSelect=document.getElementsByTagName("select");
for(var i=0;i<allSelect.length;i++){
if(allSelect[i].id=="select_user_id")
flag++;
}alert(flag);
最好的方法 还是用name属性
那 getElementsByName 就能得到了
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script type="text/javascript">
function FindSpan() {
document.writeln(document.getElementsByName("select_user_id").length);
}
</script>
</head><body>
<select multiple size=10 id="select_user_id" name="select_user_id">
<option value="1"> 1 </option>
<option value="2"> 2 </option>
</select><select multiple size=10 id="select_user_id" name="select_user_id">
<option value="a"> a </option>
<option value="b"> b </option>
</select><select multiple size=10 id="select_user_id" name="select_user_id">
<option value="q"> q </option>
<option value="f"> f </option>
</select><button value="Click me" onclick="FindSpan()"></button>
</body>
</html>