链接.add和.submit在IE中无法按预期工作

chaining .add and .submit does not work as expected in IE

本文关键字:工作 add submit IE 链接      更新时间:2023-09-26

以下语法适用于Safari(osx)、Chrome(win/osx)和Firefox(win/osx),但不适用于非城域IE 11(windows 8.1)。

var html = '<form id="theForm" name="theForm" action="/controller/action" method="POST">;
html += '<input type="hidden" name="bob" value="-1" />';
html += '</form>';
//  I expect this to work in IE as it does in all other browsers.
$(document).add(html).submit();

这是一个错误还是我做了不正确的事情?

看起来您遇到了一些链接问题。我认为您希望将html字符串附加到body元素(而不是document),然后提交form元素。使用$('BODY').append(html).sumbit();是正确的,但submit是在body元素上调用的,而不是在form元素上调用。

相反,从html字符串创建一个jQuery对象集合,将其附加到body,然后是submit

$(html).appendTo('body').submit();

示例:

var html = '<form id="theForm" name="theForm" action="/controller/action" method="POST">';
html += '<input type="hidden" name="bob" value="-1" />';
html += '</form>';
$(html).appendTo('body').submit();