javascript - Form.submit 在 FF 和 IE 中不起作用

标签 javascript jquery internet-explorer firefox form-submit

我在 Firefox 和 IE 中使用 javascript 手动提交表单时遇到问题。 Chrome和Opera中没有问题。

当用户提交表单时,我使用 javascript/jquery 拦截它,对密码进行哈希处理并重新提交表单。

我尝试了许多仅使用 javascript 的替代变体,但也不起作用。

问题还在于这个特定的代码,因为没有它,它可以完美地工作。

 window.onload = main;


function main()
{                                           // Problem with Firefox and IE
                                            // Form seems to not submit correctly after the manual submit
 $('#loginForm').submit(function(event) 
    {
        if (typeof event.originalEvent !== 'undefined') 
        {
            event.preventDefault();
        }
        else
        {
            return;
        }


        var passHash = CryptoJS.SHA256($('#password').val());
        $('#password').val(passHash.toString());

     //   document.getElementById('loginForm').submit();
        $('#loginForm').trigger('submit');
    });  
}

最佳答案

太复杂了,它只需要:

function main()
{                                           

    $('#loginForm').submit(function(event) 
    {

        var passHash = CryptoJS.SHA256($('#password').val());
        $('#password').val(passHash.toString());

        return true;
    });  
}

关于javascript - Form.submit 在 FF 和 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21453674/

相关文章:

javascript - 无法在 iOS 模拟器上运行简单的基于 KineticJs 的 Cordova/PhoneGap 应用程序

javascript - OpenTok: session 和 token 有什么区别?

javascript - Promise.all 未按预期工作,忽略 Unresolved promise

jquery - 检查输入值是否作为选择中的选项存在

internet-explorer - nth-child 在 IE7/IE8 中不工作

javascript - 尝试检测 ActiveX 插件

javascript设置对象相等

c# - WPF 工具提示 : Is there any option to Click on a Button that is inside tooltip (code and picture attached)

jquery - 国际域名 + JQuery attr ('href' ) Firefox 中的问题

jquery - 日语字符在 IE 8 中无法正确显示...不确定早期版本