javascript - 简单的 Javascript 无法在 Internet Explorer 上运行

标签 javascript

我的网站有一个安全登录表单。在登录过程中,我使用一个名为 form.js 的文件。当我输入用户名和密码时,它会加载,但不会将我定向到该页面,但在 Chrome 上一切正常。我收到此通知(单击图像链接):

enter image description here

这是 forms.js 代码:

function formhash(form, password) {
    // Create a new element input, this will be our hashed password field. 
    var p = document.createElement("input");

    // Add the new element to our form. 
    form.appendChild(p);
    p.name = "p";
    p.type = "hidden";
    p.value = hex_sha512(password.value);

    // Make sure the plaintext password doesn't get sent. 
    password.value = "";

    // Finally submit the form. 
    form.submit();
}

对这个问题有什么想法吗?

最佳答案

Internet Explorer 不允许您在将元素添加到 DOM 后更改其 type 属性。您必须在追加节点之前设置此属性。

此外,设置节点属性的正确方法是使用 setAttribute() 函数。

这应该有效:

function formhash(form, password) {
    // Create a new element input, this will be our hashed password field. 
    var p = document.createElement("input");
    p.setAttribute("name","p");
    p.setAttribute("type","hidden");
    p.setAttribute("value",hex_sha512(password.value));

    // Add the new element to our form. 
    form.appendChild(p);

    // Make sure the plaintext password doesn't get sent. 
    password.value = "";

    // Finally submit the form. 
    form.submit();
}

关于javascript - 简单的 Javascript 无法在 Internet Explorer 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21876153/

相关文章:

javascript - 获取函数的默认值?

javascript - 在迭代对象时重命名对象的键是否安全?

javascript - 可排序的 JS 使用按钮单击删除项目

javascript - Crockford 的 .supplant 多层次对象

javascript - onclick 调用 jQuery 函数

javascript - 如何动态更改标签值

javascript - 如何使两个JavaScript函数的执行互斥?

javascript - 无法从 LMS 检索以前保存的数据 - SCORM 2004

javascript - 如何让 javascript 返回这个值?

javascript - 重叠页面容器边框与 float div 边框