简体   繁体   English

我无法让我的 JavaScript 函数在资源管理器中工作

[英]I can't get my JavaScript Function to work in Explorer

I am having Trouble getting my JavaScript function to work in Internet explorer.我无法让我的 JavaScript 函数在 Internet Explorer 中工作。 It works in all browsers other then explorer.它适用于除资源管理器之外的所有浏览器。

The user clicks on a button, which calls a function that checks to see if the password is correct.用户单击一个按钮,该按钮调用一个函数来检查密码是否正确。 If its correct it takes the user to "members only page" if it is incorrect it tells the user that the password is incorrect如果正确,它会将用户带到“仅限会员页面”,如果不正确,它会告诉用户密码不正确

<script>
    function myFunction2() {
        if (PasswordTextbox2.value == "!2008Buzzer1") {
            location.href = '/JnHSDHdM3gDOEffDUt68HJHU.aspx'
        } else {
            document.getElementById("ErrorLocation").innerHTML = "Your Password is incorrect";
        }
    }
</script>
<input type="text" name="PasswordTextbox2" id="PasswordTextbox2">
<input type="button" onclick="myFunction2()" value='Submit'>
<p style="color: red" id="ErrorLocation"></p>

You should avoid referencing elements by their name / ID directly, it's a non-standard feature.您应该避免直接通过名称/ID 引用元素,这是一项非标准功能。

Instead use document.getElementById() , and the other .get* , & .query* methods exclusively.而是使用document.getElementById()和其他.get* , & .query*方法。

You should also know that storing a password in JavaScript offers no real security.您还应该知道,在 JavaScript 中存储密码并不能提供真正的安全性。 This JavaScript runs on the client's machine - anyone who has access to your page can see this password.这个 JavaScript 在客户端的机器上运行 - 任何有权访问您页面的人都可以看到这个密码。

 function myFunction2() { var password = document.getElementById('PasswordTextbox2'), error = document.getElementById("ErrorLocation"); if (password.value == "!2008Buzzer1") { location.href = '/JnHSDHdM3gDOEffDUt68HJHU.aspx'; } else { error.innerHTML = "Your Password is incorrect"; } }
 <input type="text" name="PasswordTextbox2" id="PasswordTextbox2"> <input type="button" onclick="myFunction2()" value='Submit'> <p style="color: red" id="ErrorLocation"></p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM