0

我有一个函数,当用户选中一个获取值、名称和 iframe 页面的复选框时,它会调用该函数,然后将这些信息连接起来并将其推送到数组中。这是功能。

parent.genL = new Array();
 function repGenChk() {
 var chkN = this.name;
 var chkV = this.value;
 var chkP = parent.document.getElementById("selOpt").selectedIndex;
 var chkArr = chkN+":"+chkV+":"+chkP;
 parent.genL.push(chkArr);
 alert(parent.genL[parent.genL]);
}

我遇到的问题是当它发出警报时,所有数组项都是这样的,“:undefined:X” X 是页码。对于推送到数组的每个项目,它应该看起来像这样,“3041:3041:3,1002:1002:1,10294:10294:10 ...”等等。它唯一得到的是 iframe 页面 id(在 chkP 变量中调用的 selOpt 变量。)。我假设我处理“这个”错误,但我不确定我是如何处理错误的?一个示例复选框看起来像这样......

<input type="checkbox" onclick="repGenChk();" value="9059" name="9059">

所以我希望它的工作方式是,用户通过单击复选框选择感兴趣的缩略图,复选框函数执行将“x:x:x”项推送到数组,稍后在 iframe 页面之间进行多次检查后,一些其他的东西得到完成了该信息。

非常欢迎任何和所有信息、提示、想法和建设性批评!非常感谢您对 StackOverflow 社区的帮助!

:)

4

1 回答 1

1

我认为您需要将“this”传递给repGenChk()。实际上,您没有向 repGenChk() 传递任何内容,因此 this.name 和 this.value 在 repGenChk 函数中是未定义的。

对于输入标签:

<input type="checkbox" onclick="repGenChk(this);" value="9059" name="9059">

对于 repGenChk 函数:

parent.genL = new Array();
function repGenChk(obj) {
    var chkN = obj.name;
    var chkV = obj.value;
    var chkP = parent.document.getElementById("selOpt").selectedIndex;
    var chkArr = chkN+":"+chkV+":"+chkP;
    parent.genL.push(chkArr);
    alert(parent.genL[parent.genL]);
}
于 2012-11-12T03:41:27.057 回答