【发布时间】:2011-10-11 06:31:05
【问题描述】:
我已经基于数组动态生成单选按钮。单选按钮的名称和 id 从 1 自动递增。
问题是我无法在 for 循环中访问他们的 ID 或名称。
var t;
for(var i=0; i<k.length; i++) //k is the array of values selected.
{
t = "t" + i;
// 'i' is the auto incremented radio button name and id
if (document.form1.getElementById(t).value == k[i])
{
// need 'i' to auto increment up to match radio button name and id
//document.form1.i.checked = true;
document.form1.getElementById(t) = true;
}
}
通过 XSL 构建的单选按钮:
<xsl:for-each select="a/b">
<input id="t{autoincnum}" type="radio" name="t{autoincnum}" value="{c[@value='1']/@value}"/>
<input id="t{autoincnum}" type="radio" name="t{autoincnum}" value="{c[@value='2']/@value}"/>
<input id="t{autoincnum}" type="radio" name="t{autoincnum}" value="{c[@value='3']/@value}"/>
</xsl:for-each>
【问题讨论】:
标签: php javascript html loops radio-button