为什么弹出的id不是123456

一匹野狼 2011-12-22 11:40:07
为什么弹出的不是123456而是13579呢。问题出在那里呢


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"><title>
用户列表
</title><link href="../../images/skin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
-->
</style>
<script type="text/javascript" language="javascript">

function ChangeChk(ctl)
{
var theBox=ctl;
var elem=theBox.form.elements;
var ss = new Array();
var i;
for(i=0;i<elem.length;i++)
{
if(elem[i].type=='radio')
{
if(elem[i].id==theBox.id)
{
elem[i].checked=true;
alert(i);
if(i<10)
{
i="0"+i;
}
ss[0]=document.getElementById("DataList1_ctl"+i+"_TextBox1").value;
window.returnValue = ss;
//window.close();
}
else
{
elem[i].checked=false;
}
}
}
}
</script>

</head>
<body>
<form name="form1" method="post" action="user.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTExNzk2ODAzMDcPZBYCAgMPZBYCAgEPPCsACQEADxYEHghEYXRhS2V5cxYAHgtfIUl0ZW1Db3VudAIGZGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgwFE0RhdGFMaXN0MSRjdGwwMCRDaGsFE0RhdGFMaXN0MSRjdGwwMCRDaGsFE0RhdGFMaXN0MSRjdGwwMSRDaGsFE0RhdGFMaXN0MSRjdGwwMSRDaGsFE0RhdGFMaXN0MSRjdGwwMiRDaGsFE0RhdGFMaXN0MSRjdGwwMiRDaGsFE0RhdGFMaXN0MSRjdGwwMyRDaGsFE0RhdGFMaXN0MSRjdGwwMyRDaGsFE0RhdGFMaXN0MSRjdGwwNCRDaGsFE0RhdGFMaXN0MSRjdGwwNCRDaGsFE0RhdGFMaXN0MSRjdGwwNSRDaGsFE0RhdGFMaXN0MSRjdGwwNSRDaGtfWgRX0iDsC1gnqXrFXW7p0RIJ6A==" />
</div>

<div>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="100%" height="30" bgcolor="#D5E2F2">
<span style="font-weight: bold; color: #0099FF; font-size: 20px;">用户列表</span></td>
</tr
><tr>
<td height="22">
<table id="DataList1" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;">
<tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl00_Chk" type="radio" name="DataList1$ctl00$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl00$TextBox1" type="text" value="admin" id="DataList1_ctl00_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl01_Chk" type="radio" name="DataList1$ctl01$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl01$TextBox1" type="text" value="erec" id="DataList1_ctl01_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl02_Chk" type="radio" name="DataList1$ctl02$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl02$TextBox1" type="text" value="adminn" id="DataList1_ctl02_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl03_Chk" type="radio" name="DataList1$ctl03$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl03$TextBox1" type="text" value="123m" id="DataList1_ctl03_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl04_Chk" type="radio" name="DataList1$ctl04$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl04$TextBox1" type="text" value="875545" id="DataList1_ctl04_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl05_Chk" type="radio" name="DataList1$ctl05$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl05$TextBox1" type="text" value="test" id="DataList1_ctl05_TextBox1" />
</td>
</tr>
</table>

</td>
</tr>
</table>
</td>
</tr>
</table>
</div>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWDQLWqpmqDALSiYvRBQKN3Y/fCAK/rZeKDgLYi5TcDgLI6bzWBAKHzsTlCgLNmeOSBALyy7u4CAKO/Y9wAqm/uIYBAqvt+JkMAsTGhKcJG6xWFIitxa/TidVG9TM2UwJVQwo=" />
</div></form>
</body>
</html>
...全文
207 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
BLUE_LG 2011-12-22
  • 打赏
  • 举报
回复

<script type="text/javascript" language="javascript">

function ChangeChk(ctl)
{
var theBox=ctl;
var elem=theBox.form.elements;
var ss = new Array();
var i;
var j=0;
for(i=0;i<elem.length;i++)
{
if(elem[i].type=='radio')
{
j++;//radio个数
if(elem[i].id==theBox.id)
{
elem[i].checked=true;
alert(j);
if(i<10)
{
i="0"+i;
}
ss[0]=document.getElementById("DataList1_ctl"+i+"_TextBox1").value;
window.returnValue = ss;
//window.close();
}
else
{
elem[i].checked=false;
}
}
}
}
</script>
hlke85422 2011-12-22
  • 打赏
  • 举报
回复
var theBox=ctl;ctl已经是ridio对象了
var elem=theBox.form.elements; 你是要取什么呢?
是否是this.form1.elements?
Legend1988 2011-12-22
  • 打赏
  • 举报
回复
楼主的程序写得非常乱!看了一下觉得是因为你那个radio后面还有一个input类型为text的输入框,导致弹出的不是123456而是13579。
aihua17 2011-12-22
  • 打赏
  • 举报
回复
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"><title>
用户列表
</title>
<link href="../../images/skin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
-->
</style>
<script type="text/javascript" language="javascript">

function ChangeChk(ctl)
{
var input= document.getElementsByTagName("input");
var inputa = new Array();
for(var i=0;i<input.length;i++){

if (input[i].type == "radio"){
//alert(input[i]);
inputa.push(input[i]);

}

}
for(var j=0;j<inputa.length;j++){
inputa[j].checked = false;
if(inputa[j].id == ctl.id){
alert(j+1);
inputa[j].checked = true;
}

}
//alert(form.length)

/*var theBox=ctl;
var elem=theBox.form.elements;
var ss = new Array();
var i;
for(i=0;i<elem.length;i++)
{
if(elem[i].type=='radio')
{
if(elem[i].id==theBox.id)
{
elem[i].checked=true;
alert(i);
if(i<10)
{
i="0"+i;
}
ss[0]=document.getElementById("DataList1_ctl"+i+"_TextBox1").value;
window.returnValue = ss;
//window.close();
}
else
{
elem[i].checked=false;
}
}
}*/
}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /></head>
<body>
<form name="form1" method="post" action="user.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTExNzk2ODAzMDcPZBYCAgMPZBYCAgEPPCsACQEADxYEHghEYXRhS2V5cxYAHgtfIUl0ZW1Db3VudAIGZGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgwFE0RhdGFMaXN0MSRjdGwwMCRDaGsFE0RhdGFMaXN0MSRjdGwwMCRDaGsFE0RhdGFMaXN0MSRjdGwwMSRDaGsFE0RhdGFMaXN0MSRjdGwwMSRDaGsFE0RhdGFMaXN0MSRjdGwwMiRDaGsFE0RhdGFMaXN0MSRjdGwwMiRDaGsFE0RhdGFMaXN0MSRjdGwwMyRDaGsFE0RhdGFMaXN0MSRjdGwwMyRDaGsFE0RhdGFMaXN0MSRjdGwwNCRDaGsFE0RhdGFMaXN0MSRjdGwwNCRDaGsFE0RhdGFMaXN0MSRjdGwwNSRDaGsFE0RhdGFMaXN0MSRjdGwwNSRDaGtfWgRX0iDsC1gnqXrFXW7p0RIJ6A==" />
</div>

<div>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="100%" height="30" bgcolor="#D5E2F2">
<span style="font-weight: bold; color: #0099FF; font-size: 20px;">用户列表</span></td>
</tr
><tr>
<td height="22">
<table id="DataList1" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;">
<tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl00_Chk" type="radio" name="DataList1$ctl00$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl00$TextBox1" type="text" value="admin" id="DataList1_ctl00_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl01_Chk" type="radio" name="DataList1$ctl01$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl01$TextBox1" type="text" value="erec" id="DataList1_ctl01_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl02_Chk" type="radio" name="DataList1$ctl02$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl02$TextBox1" type="text" value="adminn" id="DataList1_ctl02_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl03_Chk" type="radio" name="DataList1$ctl03$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl03$TextBox1" type="text" value="123m" id="DataList1_ctl03_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl04_Chk" type="radio" name="DataList1$ctl04$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl04$TextBox1" type="text" value="875545" id="DataList1_ctl04_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl05_Chk" type="radio" name="DataList1$ctl05$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl05$TextBox1" type="text" value="test" id="DataList1_ctl05_TextBox1" />
</td>
</tr>
</table>

</td>
</tr>
</table>
</td>
</tr>
</table>
</div>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWDQLWqpmqDALSiYvRBQKN3Y/fCAK/rZeKDgLYi5TcDgLI6bzWBAKHzsTlCgLNmeOSBALyy7u4CAKO/Y9wAqm/uIYBAqvt+JkMAsTGhKcJG6xWFIitxa/TidVG9TM2UwJVQwo=" />
</div></form>
</body>
</html>

这样不知道对不对
yuanzinen56 2011-12-22
  • 打赏
  • 举报
回复
楼主有几点我想不明白的地方:
首先,明明只作用在radio元素上,为什么要循环遍历整个form的元素?
其次,建立新数组的意义在哪里?似乎是一个普通的变量就可以传值了。

还有,我这样改对不对,有没有影响原来想要实现的功能。盼解答。
yuanzinen56 2011-12-22
  • 打赏
  • 举报
回复
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"><title>
用户列表
</title><link href="../../images/skin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
-->
</style>
<script type="text/javascript" language="javascript">

function ChangeChk(ctl)
{

var ss = new Array();
var theBox=ctl;
var ra=document.getElementsByName("DataList1$ctl00$Chk");
var i;
for(i=0;i<ra.length;i++)
{

if(ra[i].id==theBox.id)
{
ra[i].checked=true;
alert(i+1);

if(i<10)
{
i="0"+i;
}
cc=document.getElementById("DataList1_ctl"+i+"_TextBox1").value;

alert(cc);
window.returnValue = ss;

} else
{
ra[i].checked=false;
}


}
}
</script>

</head>
<body>
<form name="form1" method="post" action="user.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTExNzk2ODAzMDcPZBYCAgMPZBYCAgEPPCsACQEADxYEHghEYXRhS2V5cxYAHgtfIUl0ZW1Db3VudAIGZGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgwFE0RhdGFMaXN0MSRjdGwwMCRDaGsFE0RhdGFMaXN0MSRjdGwwMCRDaGsFE0RhdGFMaXN0MSRjdGwwMSRDaGsFE0RhdGFMaXN0MSRjdGwwMSRDaGsFE0RhdGFMaXN0MSRjdGwwMiRDaGsFE0RhdGFMaXN0MSRjdGwwMiRDaGsFE0RhdGFMaXN0MSRjdGwwMyRDaGsFE0RhdGFMaXN0MSRjdGwwMyRDaGsFE0RhdGFMaXN0MSRjdGwwNCRDaGsFE0RhdGFMaXN0MSRjdGwwNCRDaGsFE0RhdGFMaXN0MSRjdGwwNSRDaGsFE0RhdGFMaXN0MSRjdGwwNSRDaGtfWgRX0iDsC1gnqXrFXW7p0RIJ6A==" />
</div>

<div>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="100%" height="30" bgcolor="#D5E2F2">
<span style="font-weight: bold; color: #0099FF; font-size: 20px;">用户列表</span></td>
</tr
><tr>
<td height="22">
<table id="DataList1" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;">
<tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl00_Chk" type="radio" name="DataList1$ctl00$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl00$TextBox1" type="text" value="admin" id="DataList1_ctl00_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl01_Chk" type="radio" name="DataList1$ctl00$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl01$TextBox1" type="text" value="erec" id="DataList1_ctl01_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl02_Chk" type="radio" name="DataList1$ctl00$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl02$TextBox1" type="text" value="adminn" id="DataList1_ctl02_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl03_Chk" type="radio" name="DataList1$ctl00$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl03$TextBox1" type="text" value="123m" id="DataList1_ctl03_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl04_Chk" type="radio" name="DataList1$ctl00$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl04$TextBox1" type="text" value="875545" id="DataList1_ctl04_TextBox1" />
</td>
</tr>
</table>

</td>
</tr><tr>
<td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#D5E2F2">
<tr>
<td width="50%" height="22" align="center">
<input id="DataList1_ctl05_Chk" type="radio" name="DataList1$ctl00$Chk" value="Chk" onclick="ChangeChk(this);" />
<input name="DataList1$ctl05$TextBox1" type="text" value="test" id="DataList1_ctl05_TextBox1" />
</td>
</tr>
</table>

</td>
</tr>
</table>
</td>
</tr>
</table>
</div>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWDQLWqpmqDALSiYvRBQKN3Y/fCAK/rZeKDgLYi5TcDgLI6bzWBAKHzsTlCgLNmeOSBALyy7u4CAKO/Y9wAqm/uIYBAqvt+JkMAsTGhKcJG6xWFIitxa/TidVG9TM2UwJVQwo=" />
</div></form>
</body>
</html>

87,989

社区成员

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

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