我使用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>