gpt4 book ai didi

javascript - 简单的 Javascript 不适用于 Internet Explorer

转载 作者:行者123 更新时间:2023-11-29 19:42:59 24 4
gpt4 key购买 nike

我的网站有一个安全的登录表单。在登录过程中,我使用了一个名为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();
}

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

最佳答案

在将元素添加到 DOM 后,Internet Explorer 不允许您更改元素的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com