简体   繁体   English

我正在尝试结合此javascript代码?

[英]I am trying to combine this javascript code?

So, I am trying to password protect a button that shows some text on my website. 因此,我试图用密码保护在我的网站上显示一些文本的按钮。 Here is the code for the password protect script I have. 这是我拥有的密码保护脚本的代码。

<SCRIPT>
  function passWord() {
    var testV = 1;
    var pass1 = prompt('Enter The Code On Your Card Here.',' ');
    while (testV < 3) {
      if (!pass1)
        history.go(-1);
      if (pass1.toLowerCase() == "abc123") {
        window.open('card1e.html');
        break;
      }
      testV+=1;
      var pass1 =
      prompt('Access Denied - Password Incorrect, Please Try Again.','Password');
    }
    if (pass1.toLowerCase()!="password" & testV ==3)
      history.go(-1);
    return " ";
  }
</SCRIPT>
<CENTER>
  <FORM>
    <input type="button" value="Have This Card? Click Here!" onClick="passWord()">
  </FORM>
</CENTER>

The show/hide script I am using is this: 我正在使用的显示/隐藏脚本是这样的:

<script>
  <a href="javascript:hideshow(document.getElementById('adiv'))">Click here</a>

  <script type="text/javascript">
  function hideshow(which){
    if (!document.getElementById)
      return
    if (which.style.display=="block")
      which.style.display="none"
    else
      which.style.display="block"
  }
</script>

<div id="adiv" style="font:24px bold; display: block">Now you see me</div>

Is can't figure out how to get it so that when the password is entered correctly, it shows the button where you can show/hide some text. Is无法弄清楚如何获得它,以便在正确输入密码后显示密码按钮,您可以在其中显示/隐藏一些文本。

This should work 这应该工作

<!DOCTYPE html>
<html>
<head>
<SCRIPT>

    // Show Div if its hidden
    function showdiv(){

        // get the div   
        which = document.getElementById('adiv');

        // show hide
        if (!which)
            return
        else if (which.style.visibility=="hidden")
            which.style.visibility="visible";

    }

    // Test User Credentials
    function passWord(){

        var testV = 1;      
        var pass1 = prompt('Enter The Code On Your Card Here.');        // no need to give a space here
        while (testV < 3) {
            if (!pass1)
                history.go(-1);
            if (pass1.toLowerCase() == "abc123") {
                showdiv()  
                alert("Redirecting in 3 secs...")
                window.setTimeout(redirect,3000);       //wait for 3 secs then redirect to card1.html                       
                break;
            }
            testV+=1;
            var pass1 = prompt('Access Denied - Password Incorrect, Please Try Again.',"password");
        }
        if (pass1.toLowerCase()!="password" & testV ==3)
        history.go(-1);
        return " ";
    }

    function redirect(){

        window.open('card1e.html');

    }

</SCRIPT>
</head>
<body>
<div id="adiv" style="font:24px bold; visibility:hidden">Now you see me</div>
<CENTER>
<input type="button" value="Click to enter credentials toe see the text block" onClick="passWord()">  
</CENTER>
</body>

暂无
暂无

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

相关问题 我正在尝试了解以下javascript代码 - I am trying to understand the following javascript code 我正在尝试在循环时组合字符串 - I am trying to combine a string while looping 我正在尝试找出此Javascript代码出了什么问题 - I am trying to figure out what is wrong with this Javascript code 我正在尝试简化此代码 - I am trying to simplify this code 如何在 Javascript 中获取会话值,但我的 javascript 代码位于 asp.net 后面的代码中。 我正在尝试在 javascript 中设置变量值 - How to get session value in Javascript but my javascript code is in the code behind in asp.net. I am trying to set the variable value in javascript 我正在尝试结合一个 JSON 文件在谷歌地图中创建标记 - I am trying to combine a JSON file to create markers in a google maps 我试图将CORS正确地实现到我的JavaScript代码,并且工作了一段时间,我相信项目中缺少一些文件吗? - I am trying to implement CORS to my JavaScript code correctly, and it worked for a while, I believe I am missing some file from the project? 我与“ THIS” JavaScript代码堆叠在一起 - I am stack with 'THIS' javascript code 我正在尝试通过后面的代码在ASP按钮单击事件上调用javascript函数,但是我没有工作 - I am trying to call a javascript function on asp button click event through code behind but i did not work 有人可以向我解释这段代码,它是用JavaScript编写的,我正在尝试了解如何创建可观察的代码 - Can someone explain to me this code, it is in JavaScript and I am trying to understand how observable are created
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM