当我提交不完整的数据时,为什么我的要求不会触发?这是我的代码:
<form class="form-adminpage" method="post" action="admin.php">
<input type="text" name="project_title" placeholder="Project Title" required /><br>
<input type="text" name="city" placeholder="City" required /><br>
<input type="text" name="province" placeholder="Province" required /><br>
<input type="text" name="cost" placeholder="Cost" required /><br>
<input type="Submit" name="button" value="Enter" onclick="return confirm('Are you sure you want to add the following data?');">
</form>
答案 0 :(得分:1)
onclick
将首先触发。如果您想先显示HTML 5验证,可以在表单的onsubmit
事件中添加提醒
<form class="form-adminpage" method="post" action="admin.php" onsubmit="return confirm('Are you sure you want to add the following data?');">
<input type="text" name="project_title" placeholder="Project Title" required="true" /><br>
<input type="text" name="city" placeholder="City" required /><br>
<input type="text" name="province" placeholder="Province" required /><br>
<input type="text" name="cost" placeholder="Cost" required /><br>
<input type="Submit" name="button" value="Enter" >
</form>