链接 .add 和 .submit 在 IE 中无法正常工作
chaining .add and .submit does not work as expected in IE
以下语法适用于 Safari (osx)、Chrome (win/osx) 和 Firefox (win/osx) - 但不适用于非 Metro 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();
的正确轨道上,但是在 body
元素而不是 form
元素上调用 submit
。
相反,从 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();
以下语法适用于 Safari (osx)、Chrome (win/osx) 和 Firefox (win/osx) - 但不适用于非 Metro 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();
的正确轨道上,但是在 body
元素而不是 form
元素上调用 submit
。
相反,从 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();