我觉得可以让生成的复选框和后面的文本之间的id有联系,即可以从复选框的id得到后面文本的id
function fnGet()
{
var o=eval(c1.id+"_text");
alert(o.innerHTML)
}
</script>
<input type="checkbox" id="c1"><span id=c1_text>value</span>
<input type="button" onclick="fnGet()" value="click">
function fnGet()
{
var o=eval(c1.id+"_text");
alert(o.innerHTML)
}
</script>
<input type="checkbox" id="c1"><span id=c1_text>value</span>
<input type="button" onclick="fnGet()" value="click">
给你个例子吧……
/******************************** vote.htm ********************************/
<html>
<head>
<title>投票</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<script language="JavaScript">
function calculate()
{
var sum,sum2;
var chanpin=new Array("","","")
var chanpin2=new Array("","","")
sum=0;
sum2=0
for(i=0;i<document.all.aa.length;i++)
{
if (document.all.aa[i].checked==true)
{sum=sum+1
chanpin[sum-1]=document.all.aa[i].parentElement.parentElement.childNodes[0].innerText
if (sum>3)
{alert("超过三个了");
return false;
}
}
if (document.all.bb[i].checked==true)
{sum2=sum2+1
chanpin2[sum2-1]=document.all.bb[i].parentElement.parentElement.childNodes[0].innerText
if (sum2>3)
{alert("超过三个了");
return false;
}
}
document.all.t1.value=chanpin[0]
document.all.t2.value=chanpin[1]
document.all.t3.value=chanpin[2]
document.all.t4.value=chanpin2[0]
document.all.t5.value=chanpin2[1]
document.all.t6.value=chanpin2[2]
}
}
</script>
<body bgcolor="#FFFFFF" > <p> </p><form name=VoteForm method='POST'>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" align="center">
<tr>
<td>
<table border='0' cellpadding='3'rules=rows align="center" bordercolor="#000000" cellspacing='2'>
<tr bgcolor="eeeeee">
<td colspan="2" align="center">投票</td>
</tr>
<tr bgcolor="eeeeee">
<td width="187">您认为较好的产品(1-3个)是:</td>
<td width="208">
<p> </p>
<p> t1
<input type="text" name="t1" id="t1">
<br>
t2
<input type="text" name="t2" id="t2">
<br>
t3
<input type="text" name="t3" id="t3">
</p>
</td>
</tr>
<tr bgcolor="eeeeee">
<td width="187">您认为较差的产品(1-3个)是: </td>
<td width="208">
<p> t4
<input type="text" name="t4" id="t4">
<br>
t5
<input type="text" name="t5" id="t5">
<br>
t6
<input type="text" name="t6" id="t6">
</p>
</td>
</tr>
<tr bgcolor="eeeeee">
<td valign='bottom' align='center' width="187">您对我厂的服务情况:</td>
<td width="208">
<select name="select">
<option value="0">-请选择-</option>
<option value="1">满意</option>
<option value="2">较满意</option>
<option value="3">一般</option>
<option value="4">不太满意</option>
<option value="5">不满意</option>
</select>
</td>
</tr>
<tr bgcolor="#CCCCCC">
<td valign='bottom' align='center' colspan="2" class="INPUT">
<input type='button' value='投票' name='B1' onClick="SubmitVote()">
</td>
</tr> </table>
</td>
</tr>
</table> <br>
<table border="1" cellspacing="0" cellpadding="0" bordercolor="#000000" align="center" width="322">
<tr>
<td>
<table border=0 cellpadding=2 cellspacing=1 width="100%">
<tr bgcolor="eeeeee">
<td width="70%"><%if user_part = "Buyer" then %>经营企业<%else user_part = "Saler"%>医疗机构<%end if%>名称</td>
<td width="15%">较好</td>
<td width="15%">较差</td>
</tr>
<tbody>
<tr bgcolor="eeeeee">
<td width="70%">产品 1</td>
<td width="15%">
<input type="checkbox" name="aa1" id="aa"value="checkbox" >
</td>
<td width="15%">
<input type="checkbox" name="bb1" id="bb"value="checkbox">
</td>
</tr>
<tr bgcolor="eeeeee">
<td width="70%">产品 2</td>
<td width="15%">
<input type="checkbox" name="aa2" id="aa" value="checkbox">
</td>
<td width="15%">
<input type="checkbox" name="bb2" id="bb" value="checkbox">
</td>
</tr>
<tr bgcolor="eeeeee">
<td width="70%">产品 3</td>
<td width="15%">
<input type="checkbox" name="aa3" id="aa" value="checkbox">
</td>
<td width="15%">
<input type="checkbox" name="bb3" id="bb" value="checkbox">
</td>
</tr>
<tr bgcolor="eeeeee">
<td width="70%">产品 4</td>
<td width="15%">
<input type="checkbox" name="aa4" id="aa" value="checkbox">
</td>
<td width="15%">
<input type="checkbox" name="bb4" id="bb" value="checkbox" >
</td>
</tr>
<tr bgcolor="eeeeee">
<td width="70%">产品 5</td>
<td width="15%">
<input type="checkbox" name="aa5" id="aa" value="checkbox">
</td>
<td width="15%">
<input type="checkbox" name="bb5" id="bb" value="checkbox">
</td>
</tr>
<tr bgcolor="eeeeee">
<td width="70%">产品 6</td>
<td width="15%">
<input type="checkbox" name="aa6" id="aa" value="checkbox">
</td>
<td width="15%">
<input type="checkbox" name="bb6" id="bb" value="checkbox">
</td>
</tr>
<tr bgcolor="eeeeee">
<td width="70%">产品 7</td>
<td width="15%">
<input type="checkbox" name="aa7" id="aa" value="checkbox" >
</td>
<td width="15%">
<input type="checkbox" name="bb7" id="bb" value="checkbox">
</td>
</tr>
<tr bgcolor="eeeeee">
<td width="70%">产品 8</td>
<td width="15%">
<input type="checkbox" name="aa8" id="aa" value="checkbox" >
</td>
<td width="15%">
<input type="checkbox" name="bb8" id="bb" value="checkbox" >
</td>
</tr>
<tr bgcolor="eeeeee">
<td width="70%">产品 9</td>
<td width="15%">
<input type="checkbox" name="aa9" id="aa" value="checkbox" >
</td>
<td width="15%">
<input type="checkbox" name="bb9" id="bb" value="checkbox" >
</td>
</tr>
<tr bgcolor="eeeeee">
<td width="70%">产品 10</td>
<td width="15%">
<input type="checkbox" name="aa10" id="aa" value="checkbox" >
</td>
<td width="15%">
<input type="checkbox" name="bb10" id="bb" value="checkbox" >
</td>
</tr>
<tr bgcolor=#CCCCCC align="center">
<td colspan=5>
<input name=BUTTON type=button value="选好了!" onClick="javascript:calculate();">
<input name=reset type=reset value="重选!" >
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
<br><br><br>
</form>
</body>
</html>