开发者

How to make Internet Explorer understand my ad hoc jQuery forms?

开发者 https://www.devze.com 2023-02-07 14:38 出处:网络
This simple JavaScript sni开发者_如何学Cppet seems to be too complicated for Internet Explorer 8 and even 9 to understand:

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消