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