点击确定,函数buy()怎么得到选中的复选框以及后面对应的值?
在下列表单值,点击确定后,函数buy()得到勾选的复选框的值以及后面对应的值?
- VBScript code
<table width="100%" height="100%" border="0" cellspacing="0"> <tr> <td><span style=" font-size:12px"> 修改上报站点</span><img alt="关闭会员列表" src="../../images/cls.jpg" style="cursor:hand; margin-left:390px" onClick="CloseDiv();" /> </td> </tr> <tr> <td valign="top"><form name="form2" action="" method="get"> <div><table width="96%" border="0" cellspacing="0" style=" margin-left:10px"><%dim lb,uarrlb="超市,集市,其它"u=1uarr=split(lb,",")for i=0 to ubound(uarr)%> <tr> <td style="font-size:12px; height:26px; border-bottom:#E6E6E6 solid 1px"> <%=i+1%>.<%=uarr(i)%></td> </tr> <tr> <td> <ul style="margin-left:10px"> <% dim rs,sql set rs=server.CreateObject("adodb.recordset") sql="select SpotID,SpotName,SpotUserName,spotGoods from PriceSpotTable where SpotChoise='"&uarr(i)&"' order by SpotID desc " rs.open sql,conn,1,3 do while not rs.eof %> <li style="float:left; width:115px; line-height:28px; font-size:12px"><input style="margin-top:5px" name="checkname" type="checkbox" value="<%=rs("SpotName")%>" onClick="unselectall()" /><input name="g_<%=u%>" type="hidden" value="<%=rs("spotGoods")%>" /> <%=rs("SpotName")%> </li> <% u=u+1 rs.movenext loop rs.close %> </ul></td> </tr> <% next %></table> </div><div id="msgShut" align="right"><input style="margin-top:5px" name="chkall" type="checkbox" id="chkall" onClick=CheckAll(this.form) value="checkbox" /> 全选 <input name="" type="button" value="确 定" onClick="buy()"/> </div> </form> </td> </tr></table>============
我这样写为什么提示错误?
- JScript code
function buy(){ //使用innerHTML置换table里的内容var s="";var uname=document.getElementsByName("checkname"); for (var i=0;i<uname.length;i++){if (uname[i].checked==true){ var ustr=uname[i].value;var j=i+1;var gstr=document.getElementByName("g_"+j)[0].value; //这里不行、alert(gstr); }} //document.getElementById("spotlst").innerHTML=s;//document.getElementById("bgDiv").style.display = document.getElementById("msgDiv").style.display = "none"; }[解决办法]
1、getElementsByName(),你说出多的地方,函数错了,少了个s
2、不推荐使用 getElementsByName(),不是标准的dom指令
[解决办法]
var gstr=document.getElementsByName("g_"+j)[0].value;
[解决办法]
[解决办法]
用JQUERY 吧, 一个 EACH 就搞定了