0

我在下面有javascript代码,它正在工作,但在Firebug中它说

document.form1.element[i] 未定义

然后它工作正常

function set_action(){

for (var i=0;i<=3;i++)
{

    if (document.form1.PayType[i].checked == true)

        {
            var billerid = document.form1.billerid[i].value;
                            document.form1.action = billerid +"_mypag.htm";
        }
}

我的html标记如下

<form name="form1" action="...">
<input name="PayType" type="radio" value="0" id="ultipay" class="radiobtn" checked/>
<select name="billerid" class="dropbox">
<option>item1</Option>...
</select>
<input name="PayType" type="radio" value="1" id="ultipay" class="radiobtn"/>
<select name="billerid" class="dropbox">
<option>item1</Option>
</select>
<input name="PayType" type="radio" value="2" id="ultipay" class="radiobtn"/>
<select name="billerid" class="dropbox">
<option>item1</Option>...
</select>
<input name="PayType" type="radio" value="3" id="ultipay" class="radiobtn"/>
<select name="billerid" class="dropbox">
<option>item1</Option>...
</select>
<input type="button" onclick="set_action()" value="submit">
</form>

我不知道为什么我会收到这个错误。

4

1 回答 1

2

如果您只有一个名为的单选按钮PayType,那么您需要使用document.form1.PayType. document.form1.PayType[i]如果有多个具有相同名称的单选按钮,则将其作为数组寻址。例如:

<input name="PayType" type="radio" value="0" id="ultipay0" class="radiobtn" checked="checked" />
<input name="PayType" type="radio" value="1" id="ultipay1" class="radiobtn" />
于 2013-01-21T13:41:18.377 回答