「javascript」パスワード入力欄の値を取得する

2021年12月24日

書式
const 変数名 = document.getElementById(セレクタid);
変数名.value
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<p>パスワード: <span id="pwd"></span></p>
<input type="password" value="1234go" id="userid" maxlength="8" />
<input type="button" value="検証" onclick="tesFunc()" />
<script>
function tesFunc() {
const uid = document.getElementById("userid");
//ボタンを押すとパスワードのvalue値を取得
document.getElementById("pwd").textContent = uid.value;
}
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <p>パスワード: <span id="pwd"></span></p> <input type="password" value="1234go" id="userid" maxlength="8" /> <input type="button" value="検証" onclick="tesFunc()" /> <script> function tesFunc() { const uid = document.getElementById("userid"); //ボタンを押すとパスワードのvalue値を取得 document.getElementById("pwd").textContent = uid.value; } </script> </body> </html>
<!DOCTYPE html>
<html>
<body>

<p>パスワード: <span id="pwd"></span></p>
<input type="password" value="1234go" id="userid" maxlength="8" />
<input type="button" value="検証" onclick="tesFunc()" />

<script>
  function tesFunc() {
    const uid = document.getElementById("userid");
    //ボタンを押すとパスワードのvalue値を取得
    document.getElementById("pwd").textContent = uid.value;
  }
</script>

</body>
</html>

動作確認
ボタンを押すとパスワードのvalue値を取得します

JavaScript

Posted by arkgame