<script type="text/JavaScript">
function newInput(NIFormName,NIname,NIvalue,NItype='hidden'){
var theForm = document.forms[NIFormName];
var input = document.createElement('input');
input.type = NItype;
input.name = NIname;
input.value = NIvalue;
theForm.appendChild(input);
return true;
}
</script>
这似乎适用于FF但不适用于IE 11.
所以,我做了一个搜索,看起来我需要一个不同的方法,我尝试了:
<script type="text/JavaScript">
function newInput(NIFormName,NIname,NIvalue,NItype='hidden'){
var theForm = document.forms[NIFormName];
var input = document.createElement('input');
input.setAttribute('type', NItype);
input.setAttribute('name', NIname);
input.setAttribute('value', NIvalue);
theForm.appendChild(input);
return true;
}
</script>
它仍可在FF 26中运行,但在IE中不起作用。
当我说“它不起作用”时,我的意思是我看到没有错误,并且该字段未添加到提交的数据中。
这是我表格的顶部:
<form name="writenew" method="get" action="formtest.php" onSubmit="newInput('writenew','first_added_field','Yep! I was added.');">
这是formtest.php
<?php
var_export($_GET);
?>
当我用FF提交时,它包含在显示器中
'first_added_field'=&gt; “是的!我加入了。',
但在IE中并非如此。
如何在IE中完成这项工作?