页面:源码太多,删减后部分:
<table cellspacing="0" class="datatable">
<tr class="coltitle">
<td style="height: 23px">选择</td>
</tr>
<% int i = 0;
IEnumerator ie = listTabInvoice.GetEnumerator();
string strinovic = "";
while (ie.MoveNext())
{
Cas.Entity.NHibernate.TabInvoice obj = (Cas.Entity.NHibernate.TabInvoice)(ie.Current);
strinovic += obj.Invoiceid + ",";
//hidinovices.Value += obj.Invoiceid + ",";
%>
<tr>
<td style="height: 27px">
<input type="checkbox" value="<%=obj.Invoiceid%>" id="chkchild" name="groupchk" />
</td>
</tr>
<%
i++;
}
hidinovices.Value = strinovic.TrimEnd(',');
%>
</table> <input type="button" name="Button1" class="button" value="合并Invoice" onclick="AA();" style="width: 158px"/>
JS:function AA(){
var invoices="";
FALSE: var length1 = document.form1.groupchk.length;。
alert(length1);//当数据为一条时不能取到值,弹出undefined TRUE: var length2=document.getElementsByName("groupchk").length;
alert(length2);//弹出 1
} 问:
①document.form1.groupchk.length和document.getElementsByName("groupchk").length这两种写法的区别?
②当数据为多条时,它们弹出的条数是一样的,当数据为1条时,document.form1.groupchk.length为未定义,为什么?
<table cellspacing="0" class="datatable">
<tr class="coltitle">
<td style="height: 23px">选择</td>
</tr>
<% int i = 0;
IEnumerator ie = listTabInvoice.GetEnumerator();
string strinovic = "";
while (ie.MoveNext())
{
Cas.Entity.NHibernate.TabInvoice obj = (Cas.Entity.NHibernate.TabInvoice)(ie.Current);
strinovic += obj.Invoiceid + ",";
//hidinovices.Value += obj.Invoiceid + ",";
%>
<tr>
<td style="height: 27px">
<input type="checkbox" value="<%=obj.Invoiceid%>" id="chkchild" name="groupchk" />
</td>
</tr>
<%
i++;
}
hidinovices.Value = strinovic.TrimEnd(',');
%>
</table> <input type="button" name="Button1" class="button" value="合并Invoice" onclick="AA();" style="width: 158px"/>
JS:function AA(){
var invoices="";
FALSE: var length1 = document.form1.groupchk.length;。
alert(length1);//当数据为一条时不能取到值,弹出undefined TRUE: var length2=document.getElementsByName("groupchk").length;
alert(length2);//弹出 1
} 问:
①document.form1.groupchk.length和document.getElementsByName("groupchk").length这两种写法的区别?
②当数据为多条时,它们弹出的条数是一样的,当数据为1条时,document.form1.groupchk.length为未定义,为什么?
解决方案 »
- js问题求高人解答。
- 请帮我加一个实时读取的txt方法吧
- 使用wsdl2js生成js文件,如何在javascript中调用?
- 救命啊,object对象中的MeterLibrary是怎么回事啊??
- js文件中 能够嵌入 vbs脚本么? 怎么写?
- 有关window.open的问题(在线)
- 如何让浏览器端打开我的网页时自动下载并运行一个可执行程序。
- 如何实现在页面上对一个button对象的拖动
- html中可以让一个控件写满位后自动跳到TAG键所对应的下一个控件上吗?
- html5游戏开发,有什么著名、流行的框架吗?
- 如何延迟10秒再执行下句
- Javascript的setInterval使用中遇到的问题
①document.form1.groupchk.length和document.getElementsByName("groupchk").length这两种写法的区别?
document.form1.groupchk.length
是通过form表单元素找到下面的item文本域元素,如果名称一样的就是array,才有length
如果名称都不同只有一个就不是array,就是单独一个元素。所以length就没有定义了
②当数据为多条时,它们弹出的条数是一样的,当数据为1条时,document.form1.groupchk.length为未定义,为什么?
document.form1.groupchk一条的时候也就是name都不相同,这个时候应该默认是一个html element
不是一组ele,一组是name有相同的,才是array。所以才未定义