【发布时间】:2011-11-12 17:29:36
【问题描述】:
我有一个用于进行测试的表格。用户输入问题并提供问题类型和答案选项并保存问题。出了问题的是,当用户编写一个选项并单击添加到选项的按钮时,选项的文本框的内容被添加到 DOM 以显示为问题的答案。这一切都运行良好,直到 IE9 不存在。
当用户单击“添加到选项”按钮时,该选项显示在 DOM 中,但该值未在 IE9 中发布。
将 Option 添加到 DOM 的函数是
var tbl = document.getElementById('tbl');
var lastRow = tbl.rows.length;
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
arr[ind] = iteration;
var cellLeft1 = row.insertCell(0);
var cellLeft2 = row.insertCell(1);
var cellLeft3 = row.insertCell(2);
if(document.crt_question.test_ans_view[0].checked)
{
if(document.crt_question.test_ans_choice.value=="0") // MCQ with Single Answer (Radio Buttons)
{
var op_val=document.crt_question.test_answer.value;
var words=op_val.split("");
op_val='';
for(i=0;i<words.length;i++)
{
op_val = op_val + words[i].replace('"',"'");
}
cellLeft1.innerHTML = '<div id="button_div'+ind+'" class="dom_"><input type="radio" name="button_'+ind+'" id="button_'+ind+'" value="'+ind+'" ></div>';
cellLeft2.innerHTML = '|<input type="image" src="../../_images/view_del.gif" onclick="return removeRowFromTable('+ ind +')" />|';
var newOption = document.createElement("input");
newOption.name = "test_answer"+ind+"";
newOption.type = "hidden";
newOption.value = op_val;
var newOption2 = document.createElement("input");
newOption2.name = "view_option"+ind+"";
newOption2.type = "text";
newOption2.value = op_val;
cellLeft3.appendChild(newOption);
cellLeft3.appendChild(newOption2);
ind++;
remove++;
}
}
添加选项的表是
<table id="tbl" border="0" style="padding-left:70px;">
<tr>
<td align="left"></td>
<td align="left" ></td>
<td align="left"></td>
</tr>
</table>
在表单提交时,在顶部函数中,我没有得到隐藏值或输入类型文本字段的值。这适用于 FF 和 IE8。这玩意谁可以上?
注意:此代码在通过 IFRAME 包含的文件中运行。
【问题讨论】:
-
我也有同样的问题:iframe 中的表单,使用 javascript 创建的字段没有发布。我确认在标题中添加 是可以的,但它很丑陋。有人找到另一种方法来解决这个问题吗?
标签: javascript cross-browser internet-explorer-9 dynamic