javascript - 停用上一个命令

标签 javascript css html

所以我正在尝试为一个元素创建一个页面,当您在确认窗口中单击“确定”时,它会将您带到一个登录论坛(有效)。但是,如果您单击取消,则不会加载登录论坛并将您带到其他地方。我该怎么做?我是 Javascript 的新手,所以很抱歉我的问题不清楚。这是我的代码:

// variable information

var person = {
  name: " Alex, ",
  age: " 27 years old, ",
  height: "183cm, ",
  born: " born January 12th 1996, ",
  weight: " 130 Lb "

};

window.alert("Information. Click ok to continue");

//confirm box, determines if forum loads or not... or thats the plan.

{
  if (confirm("All information in this is to remain private. Do not share any information given. Please accept these conditions.") == true) {
    alert("Now loading file information. Please wait a moment...");

    //number of attempts

    var attempt = 3;

    // executes on click below

    function validate() {
      var username = document.getElementById("username").value;
      var password = document.getElementById("password").value;
      if (username == "Correct" && password == "1141") {
        alert("Login successfully");

        var x = person.age;
        var y = person.name;
        var z = person.born;
        var a = person.height;
        var b = person.weight;

        document.write(y);
        document.write(x);
        document.write(z);
        document.write(a);
        document.write(b);

        return false;

      } else {
        // chances available. 

        alert("incorrect login. You have " + attempt + " attempt;");

        // Disables after 2 attempts 

        if (attempt == 0) {
          document.getElementById("username").disabled = true;
          document.getElementById("password").disabled = true;
          document.getElementById("submit").disabled = true;
          return false;
        }
      }
    }
  }
  // if false 
  else

    alert("Could not load. Error 707.");
}
@import url(http://fonts.googleapis.com/css?family=Raleway);
h2 {
  background-color: #FEFFED;
  padding: 30px 35px;
  margin: -10px -50px;
  text-align: center;
  border-radius: 10px 10px 0 0;
}

hr {
  margin: 10px -50px;
  border: 0;
  border-top: 1px solid #ccc;
  margin-bottom: 40px;
}

div.container {
  width: 900px;
  height: 610px;
  margin: 35px auto;
  font-family: 'Raleway', sans-serif;
}

div.main {
  width: 300px;
  padding: 10px 50px 25px;
  border: 2px solid gray;
  border-radius: 10px;
  font-family: raleway;
  float: left;
  margin-top: 50px;
}

input[type=text],
input[type=password] {
  width: 100%;
  height: 40px;
  padding: 5px;
  margin-bottom: 25px;
  margin-top: 5px;
  border: 2px solid #ccc;
  color: #4f4f4f;
  font-size: 16px;
  border-radius: 5px;
}

label {
  color: #464646;
  text-shadow: 0 1px 0 #fff;
  font-size: 14px;
  font-weight: bold;
}

center {
  font-size: 32px;
}

.note {
  color: red;
}

.valid {
  color: green;
}

.back {
  text-decoration: none;
  border: 1px solid rgb(0, 143, 255);
  background-color: rgb(0, 214, 255);
  padding: 3px 20px;
  border-radius: 2px;
  color: black;
}

input[type=button] {
  font-size: 16px;
  background: linear-gradient(#ffbc00 5%, #ffdd7f 100%);
  border: 1px solid #e5a900;
  color: #4E4D4B;
  font-weight: bold;
  cursor: pointer;
  width: 100%;
  border-radius: 5px;
  padding: 10px 0;
  outline: none;
}

input[type=button]:hover {
  background: linear-gradient(#ffdd7f 5%, #ffbc00 100%);
}
<!DOCTYPE html>
<html>

<head>
  <title>Javascript Login Form Validation</title>

  <!-- Include CSS File Here -->

  <link rel="stylesheet" href="css/style.css" />

  <!-- Include JS File Here -->

  <script src="js/login.js"></script>

</head>

<body>

  <div class="container">
    <div class="main">
      <h2>Javascript Login Form Validation</h2>
      <form id="form_id" method="post" name="myform">

        <label>User Name :</label> <input type="text" name="username" id="username" />

        <label>Password :</label> <input type="password" name="password" id="password" /> <input type="button" value="Login" id="submit" onclick="validate()" /> </form>
enter code here
</body>

</html>

最佳答案

我相信这就是您要找的。

if (confirm("All information in this is to remain private. Do not share any information given. Please accept these conditions.") == true) {
   //...
} else {
    window.location.href = "http://stackoverflow.com";
}

关于javascript - 停用上一个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43794319/

相关文章:

javascript - .prop() 和 twitter Bootstrap 模式对话框

javascript - 这个 JavaScript 有什么问题? - 采访蛋糕

css - 如何向包含已访问链接的列表元素添加样式?

javascript - 改变背景颜色

html - 不同尺寸的 ul 对齐

javascript - 使用canvas在javascript中绘制一个正方形

javascript - 事件上的鼠标指针位置未以 THREE.js 上的箭头提示为中心

html - 如何让所有item都缩小到二维最大的item内容?

c# - 为什么 ASP.NET MVC 应用程序意外地多次加载 Bootstrap

php - 是否可以使用 cookie 制作 "add to favorites"功能?