当 javascript 在客户端关闭时,如何对表单使用 html 验证
How does one uses html validation for a form when javascript is off on the client side
当 javascript 关闭时,如何通过 HTML 进行验证?通过 onclick 我的按钮将从 javascript 调用表单验证。但是,如果用户关闭 javascript,我的 HTML 验证应该是验证,如果 javascript 关闭,作为故障保护,但每当我点击我的按钮时,什么都没有发生。为什么?
<form class="reservationForm">
<h1>RESERVATION FORM</h1>
<section class="form-group">
<label>First Name:*</label>
<input type="text" class="form-control" placeholder="Enter first name" id="fname" pattern="[A-Za-z]{99}" title="Please input a name" required>
<label>Last Name:*</label>
<input type="text" class="form-control" placeholder="Enter last name" id="lname" pattern="[A-Za-z]{99}" title="Please input a name" required>
<label>Email address:*</label>
<input type="email" class="form-control" placeholder="Enter email" id="resemail" pattern="([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$" title="Please input a valid email" required>
<label>Contact Number:*</label>
<input type="tel" class="form-control" placeholder="Enter contact number" id="cnumber" pattern="[\d]{8}" maxlength="8" title="please input a valid number" required>
<label>Date:*</label>
<input type="date" class="form-control" id="resdate" required>
<p>
<label>Time:*</label> <br>
<select name="time">
<option>5:00 PM</option>
<option>6:00 PM</option>
<option>7:00 PM</option>
<option>8:00 PM</option>
<option>9:00 PM</option>
<option>10:00 PM</option>
</select>
</p>
<label>Number of people:*</label>
<input type="tel" class="form-control" placeholder="Enter pax" id="pax" pattern="[\d]{3}" maxlength="3" title="Please input a vaid number" required>
<label>Request:</label><br>
<textarea id="comment" placeholder="Request"></textarea>
</section>
<button type="button" class="btnform" onclick="return validateReservationForm() ">Submit Reservation</button>
</form>
您的按钮必须有 type="submit"
才能提交表单。
当 javascript 关闭时,如何通过 HTML 进行验证?通过 onclick 我的按钮将从 javascript 调用表单验证。但是,如果用户关闭 javascript,我的 HTML 验证应该是验证,如果 javascript 关闭,作为故障保护,但每当我点击我的按钮时,什么都没有发生。为什么?
<form class="reservationForm">
<h1>RESERVATION FORM</h1>
<section class="form-group">
<label>First Name:*</label>
<input type="text" class="form-control" placeholder="Enter first name" id="fname" pattern="[A-Za-z]{99}" title="Please input a name" required>
<label>Last Name:*</label>
<input type="text" class="form-control" placeholder="Enter last name" id="lname" pattern="[A-Za-z]{99}" title="Please input a name" required>
<label>Email address:*</label>
<input type="email" class="form-control" placeholder="Enter email" id="resemail" pattern="([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$" title="Please input a valid email" required>
<label>Contact Number:*</label>
<input type="tel" class="form-control" placeholder="Enter contact number" id="cnumber" pattern="[\d]{8}" maxlength="8" title="please input a valid number" required>
<label>Date:*</label>
<input type="date" class="form-control" id="resdate" required>
<p>
<label>Time:*</label> <br>
<select name="time">
<option>5:00 PM</option>
<option>6:00 PM</option>
<option>7:00 PM</option>
<option>8:00 PM</option>
<option>9:00 PM</option>
<option>10:00 PM</option>
</select>
</p>
<label>Number of people:*</label>
<input type="tel" class="form-control" placeholder="Enter pax" id="pax" pattern="[\d]{3}" maxlength="3" title="Please input a vaid number" required>
<label>Request:</label><br>
<textarea id="comment" placeholder="Request"></textarea>
</section>
<button type="button" class="btnform" onclick="return validateReservationForm() ">Submit Reservation</button>
</form>
您的按钮必须有 type="submit"
才能提交表单。