Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我使用html创建了两个名为用户名和密码的文本框,我想检查用户名和密码是否匹配,是否使用javascript 函数按钮单击(){ if(document.getElementById(“txt1”).value==document.getElementById(“txt2”).value){ 警报(“用户名和密码匹配”); } 否则{ 警报(“用户名和密码不匹配”); } }_Javascript_Html - Fatal编程技术网

我使用html创建了两个名为用户名和密码的文本框,我想检查用户名和密码是否匹配,是否使用javascript 函数按钮单击(){ if(document.getElementById(“txt1”).value==document.getElementById(“txt2”).value){ 警报(“用户名和密码匹配”); } 否则{ 警报(“用户名和密码不匹配”); } }

我使用html创建了两个名为用户名和密码的文本框,我想检查用户名和密码是否匹配,是否使用javascript 函数按钮单击(){ if(document.getElementById(“txt1”).value==document.getElementById(“txt2”).value){ 警报(“用户名和密码匹配”); } 否则{ 警报(“用户名和密码不匹配”); } },javascript,html,Javascript,Html,字段。setCustomValidity(“无效字段”)将使字段无效 功能按钮单击(){ if(document.getElementById(“txt1”).value==document.getElementById(“txt2”).value){ 警报(“用户名和密码匹配”); document.getElementById(“txt2”).setCustomValidity(“无效字段”); } 否则{ 警报(“用户名和密码不匹配”); } } 用户名: 密码: 点击我 提交 函数

字段。setCustomValidity(“无效字段”)将使字段无效

功能按钮单击(){
if(document.getElementById(“txt1”).value==document.getElementById(“txt2”).value){
警报(“用户名和密码匹配”);
document.getElementById(“txt2”).setCustomValidity(“无效字段”);
}
否则{
警报(“用户名和密码不匹配”);
}
}
用户名:
密码:
点击我





提交 函数checkAction(){ if(document.getElementById(“firstField”).value==document.getElementById(“secondField”).value){ 警报(“Pasword Mathced”); }否则{ 警报(“密码不匹配”); } }
我觉得不错。有什么问题吗?
<script type="text/javascript">
  function buttonclick(){
    if(document.getElementById("txt1").value==document.getElementById("txt2").value){
      alert("user name and password are matched");
    }
    else{
      alert("user name and password are not matched");
    }
  }

  </script>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
 <input type="text" placeholder="Enter the password" id="firstField"><br><br>
 <input type="text" placeholder="ReEnter the password to confirm" id="secondField"><br><br>
<button onclick="checkAction()">Submit</button>

<script>

function checkAction() {
    if(document.getElementById("firstField").value==document.getElementById("secondField").value) {
        alert("Pasword Mathced");
    } else {
        alert("Password donot matched");
    }
}

</script>
</body>
</html>