它没有进入 JS 函数,而是直接进入 process.php idk 为什么

it doesnt go the JS function and goes straightly to process.php idk why

<script>
function hi(){
alert("hi"); //assuming this is the validation

}
 </script>

 <form action="process/register.php" method="POST" onSubmit="hi()"  name="register-form">

<button type="submit" value="submit" name="submit">Register</button>
</script.

不知道为什么不通过JS函数hi();

直接直接处理

我确定我的代码是正确的。需要帮助。

如果你想让它停止提交到新页面,你可以做很多事情,举两个例子:

onsubmit="hi(); return false;" <!--Makes sure the form doesn't submit after calling your function-->

onsubmit="hi(event);" <!--Pass the event as parameter-->

然后在hi()函数中

function hi(e) {
    alert("hi");
    e.preventDefault(); //stops event from posting form. this is why we sent the event as param.
    return false; //extra measure to make sure. (not required)
}
<form action="process/register.php" method="POST" onSubmit="return hi()"  name="register-form">

请记住 return 该函数中的 true 或 false。