HTML novalidate 屬性
HTML novalidate 屬性定義當提交表單時,表單資料不應該在 HTML 文件中被驗證。
語法
以下是語法 −
<form novalidate></form>
讓我們看一個 HTML novalidate 屬性例項 −
例項
<!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>輸出

嘗試在文字框中不輸入任何名字而單擊“提交”按鈕,它會產生警告資訊 −

現在單擊“設定無驗證”按鈕,在表單元素上設定 novalidate 屬性,並且現在嘗試在文字框中不輸入任何名字而提交表單,這次它將輕鬆提交,而不會顯示任何警告資訊
−

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP