This simple JavaScript sni开发者_如何学Cppet seems to be too complicated for Internet Explorer 8 and even 9 to understand:
// Why on the (expletive) hell does Internet Explorer exist?
$('<form/>'>.attr('action', '..') // or ../index.php
.attr('method', 'post')
.append(hiddenParam('user', $('#name').val())
.append(hiddenParam('pass', cryptoFunc($('#pswd').val())
.submit().remove();
Is there any equivalent to my code that doesn't involve much rewriting? (I have quite a lot of these ad hoc jQuery-generated forms in my site.)
What happens if you add .appendTo(document.body)
just before .submit
? E.g.:
$('<form/>').attr('action', '..') // or ../index.php
.attr('method', 'post')
.append(hiddenParam('user', $('#name').val())
.append(hiddenParam('pass', cryptoFunc($('#pswd').val())
.appendTo(document.body)
.submit().remove();
And if that doesn't do it, try giving the browser a moment to catch its breath:
var form = $('<form/>');
form.attr('action', '..') // or ../index.php
.attr('method', 'post')
.append(hiddenParam('user', $('#name').val())
.append(hiddenParam('pass', cryptoFunc($('#pswd').val())
.appendTo(document.body);
setTimeout(function() {
form.submit().remove();
}, 0);
精彩评论