我有一个函数可以在 javascript 中创建一个表单并提交它。它在 Safari、Chrome、FF 和 Opera 中按预期工作,但在 IE 10 中不工作。
当 from 提交时,浏览器没有指向 IE 中 action 属性中的 url。我敢肯定这是蹩脚的,但我找不到问题,所以任何帮助将不胜感激。
function checkout() {
var myDoc = 'some xml data to send'
var form = document.createElement("form");
form.setAttribute( "method", "POST" );
form.setAttribute( "action", "http://domain.com/script.php" );
var hiddenField = document.createElement("input");
hiddenField.setAttribute( "type", "hidden" );
hiddenField.setAttribute( "name", "myField" );
hiddenField.setAttribute( "value", myDoc );
form.appendChild(hiddenField);
form.submit();
}
感谢您的帮助!!!
最佳答案
在 Internet Explorer 上,您必须将表单附加到文档(我不知道这是错误还是功能)。
简单地做
form.style.display = 'none'; // useful if you're targeting another window
document.body.appendChild(form);
关于Javascript 表单无法在 Internet Explorer 上按预期提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24282351/