页面:源码太多,删减后部分:
<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为未定义,为什么?
当一个时document.form1.groupchk返回元素,没有length属性