在提交表单之前尝试用 Javascript 匹配两个字段

Trying To Match Two Fields Before Form Submit With Javascript

我试图在提交表单之前将两个字段与我 javascript 中的结果相匹配,但无法正常工作。

如果结果不匹配,我不希望提交表单。

请问有什么解决办法?谢谢

下面的代码;

function Check(){
    var done=0;
    var check=document.check.phone.value;
    var check=document.check.pcode.value;
    
    if (phone=="08023" && pcode=="12345") {
 alert ("Result Match!");
              
                done=1;
return fasle;

    }
    if (done==0) {
   
alert("Result Don't Match!");

}
}
<form action=" " method="post">
 
<input name="phone" maxlength="11"  type='tel' id="phone" placeholder="0000-000-0000" required="" />
          <br/><br/>
             
<input name="pcode" maxlength="11"  type='tel' id="pcode" placeholder="0000-000-0000" required="" />

<br/><br/>

 <button class="button" onClick="javascript:Check()"  name="Submit" type="submit" value="Login"><span>Log In </span></button> 

</form>

你的代码有几个错误,我已经为你清理了一下。

        function Check() {
            var done = 0;
            var phone = document.check.phone.value;
            var pcode = document.check.pcode.value;

            if (phone=="08023" && pcode=="12345") {
                alert("Result Match!");
                done = 1;
            } else {
                alert("Result Don't Match!");
            }
        }
    <form name="check" action=" " method="post">
        <input name="phone" maxlength="11" type='tel' id="phone" placeholder="0000-000-0000" required="" />
        <br /><br />
        <input name="pcode" maxlength="11" type='tel' id="pcode" placeholder="0000-000-0000" required="" />
        <br /><br />
        <button class="button" onClick="javascript:Check()" name="Submit" type="submit" value="Login">
            <span>LogIn</span></button>
    </form>