0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

javascript勉強#1

Posted at

圧倒的個人的なアウトプット用記事

pythonでかなり基礎は既にあるのでそこそこ進めれたかな?()
1年前、python自体初心者of初心者なときにjsを始めようとした時とは全く感じ方が違った。htmlも学ぶのがめんどくさく感じたけど改めて今やってみると楽しい。ある程度出来るようになったらtypescriptもやってみたい。

htmlファイル

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>html-test</title>
    <script src="/main.js"></script>
    <link rel="stylesheet" href="/main.css">

</head>
<body>
    <h3>サインイン</h3>
    <p>ユーザー名<input type="username" id = "login_username"></p>
    <p>パスワード<input type="password" id = "login_password"></p>
    <button onclick="login_button()">ログイン</button>
    <p id="error_data"></p>

    <h3>登録</h3>
    <p>ユーザー名<input type="username" id = "set_username"></p>
    <p>パスワード<input type="password" id = "set_password"></p>
    <button onclick="set_button()">登録</button>
</body>
</html>

javascriptファイル

let login_data = {};

function login_button(){ // ログイン
    let login_username = document.getElementById("login_username").value;
    let login_password = document.getElementById("login_password").value;
    if (login_username in login_data){
        if (login_data[login_username] == login_password){
            document.getElementById("error_data").innerText = "ログインに成功しました"
        }else{
            document.getElementById("error_data").innerText = "パスワードが違います"
        }
    }else{
        document.getElementById("error_data").innerText = "そのユーザーは存在しません"
    }
    
}

function set_button(){ // 登録
    let set_username = document.getElementById("set_username").value;
    let set_password = document.getElementById("set_password").value;
    login_data[set_username] = set_password;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?