瀏覽代碼

10.2 password

pocu46 4 年之前
父節點
當前提交
fac5a808eb
共有 3 個文件被更改,包括 115 次插入0 次删除
  1. 18 0
      10.2 oop/index.html
  2. 85 0
      10.2 oop/script.js
  3. 12 0
      10.2 oop/style.css

+ 18 - 0
10.2 oop/index.html

@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <link rel="stylesheet" href="./style.css">
+    <title>Hometask 10.2 (OOP)</title>
+</head>
+
+<body>
+        <div class="task1" id="task1">Task 1</div>
+        <div class="task2" id="task2">Task 2</div>
+
+    <script src="./script.js"></script>
+</body>
+
+</html>

+ 85 - 0
10.2 oop/script.js

@@ -0,0 +1,85 @@
+//-------------------------------------------------------Password--------------------------------------------------------------------
+
+function Password(parent, open = false) {
+    let password = document.createElement("input");
+    parent.append(password);
+    password.setAttribute("type", open ? "text" : "password");
+    let showPassword = document.createElement("input");
+    parent.append(showPassword);
+    showPassword.setAttribute("type", "checkbox");
+
+    showPassword.checked = open;
+
+    showPassword.onclick = () => {
+        password.setAttribute("type", showPassword.checked ? "text" : "password");
+    }
+
+    password.oninput = () => {
+        this.onChange(password.value);
+    }
+
+    this.onChange = () => {};
+
+    this.setPassword = function (someVal) {
+        password.value = someVal;
+    }
+
+    this.getPassword = function () {
+        return password.value;
+    }
+}
+
+let form1 = new Password(task1, true);
+
+form1.setPassword("qwerty");
+
+console.log(form1.getPassword());
+
+//-------------------------------------------------------LoginForm--------------------------------------------------------------------
+
+function Password2(parent, open = false) {
+    let password = document.createElement("input");
+    parent.append(password);
+    password.setAttribute("type", open ? "text" : "password");
+    password.setAttribute("placeholder",  "Password");
+
+    let showPassword = document.createElement("input");
+    parent.append(showPassword);
+    showPassword.setAttribute("type", "checkbox");
+
+    let login = document.createElement("input");
+    parent.append(login);
+    login.setAttribute("type", "text");
+    login.setAttribute("placeholder",  "Login");
+
+    let loginButton = document.createElement("button");
+    parent.append(loginButton);
+    loginButton.innerText = "__OK__";
+    loginButton.disabled = true;
+
+    showPassword.checked = open;
+
+    showPassword.onclick = () => {
+        password.setAttribute("type", showPassword.checked ? "text" : "password");
+    }
+
+    password.oninput = () => {
+        this.onChange(password.value);
+    }
+
+    this.onChange = () => {};
+
+    this.setPassword = function (someVal) {
+        password.value = someVal;
+    }
+
+    this.getPassword = function () {
+        return password.value;
+    }
+
+    // if(password.value && login.value) {
+    //     loginButton.disabled = falce;
+    // }
+}
+
+let form2 = new Password2(task2, true);

+ 12 - 0
10.2 oop/style.css

@@ -0,0 +1,12 @@
+* {
+    margin: 0;
+    padding: 0;
+}
+
+div {
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    text-align: center;
+    margin-bottom: 15px;
+}