แอตทริบิวต์ HTML novalidate กำหนดว่าขณะส่งแบบฟอร์ม ข้อมูลแบบฟอร์มไม่ควรตรวจสอบในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
<form novalidate></form>
ให้เรามาดูตัวอย่าง HTML novalidate Attribute −
ตัวอย่าง
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
text-align: center;
}
input[type='text'] {
width: 300px;
padding: 8px 16px;
border: 2px solid #fff;
background: transparent;
border-radius: 20px;
display: block;
margin: 1rem auto;
outline: none;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 20px;
width: 330px;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
::placeholder {
color: #000;
}
</style>
<body>
<h1>HTML novalidate attribute Demo</h1>
<form>
<input type="text" placeholder="Enter your name" required>
<input type="submit" value="Submit" class="btn" onclick='check()'>
</form>
<button type='button' class="btn" onclick="set()">Set No Validation</button>
<div class="show"></div>
<script>
function set() {
document.querySelector('form').setAttribute('novalidate', 'true');
}
</script>
</body>
</html> ผลลัพธ์

ลองคลิกที่ปุ่ม "ส่ง" โดยไม่ใส่ชื่อในช่องข้อความ มันจะสร้างข้อความเตือน -

ตอนนี้คลิกที่ “ตั้งค่าไม่มีการตรวจสอบ ” เพื่อตั้งค่า ปรับปรุง แอตทริบิวต์บนองค์ประกอบแบบฟอร์มและตอนนี้พยายามส่งแบบฟอร์มโดยไม่ต้องป้อนชื่อใด ๆ ในช่องข้อความ คราวนี้จะถูกส่งอย่างง่ายดายโดยไม่แสดงข้อความเตือนใด ๆ
−
