h5內建表單預設氣泡修改

來源:互聯網
上載者:User

標籤:check   line   eve   UNC   tde   list   add   mit   inpu   

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title></title>
<style>
.oneline {
line-height: 1.5;
margin: 10px auto;
}

.oneline label {
width: 100px;
text-indent: 15px;
font-size: 14px;
font-family: "Microsoft Yahei";
display: inline-block;
}

.oneline .sinput {
width: 60%;
height: 30px;
border-radius: 6px;
border: 1px solid #e2e2e2;
}

.oneline input[type="submit"] {
margin-left: 20px;
width: 80px;
height: 30px;
border: 0;
background-color: #5899d0;
color: #fff;
font-size: 14px;
border-radius: 6px;
}

.error-messages {
color: red;
}
</style>
</head>
<body>
<form id="forms">
<div class="oneline">
<label for="name">使用者名稱:</label>
<input id="name" class="sinput" name="name" type="text" required>
</div>
<div class="oneline">
<label for="email">Email:</label>
<input id="email" class="sinput" name="email" type="email" required>
</div>
<div class="oneline">
<input type="submit" id="submits" value="提交">
</div>
</form>
<script>
function replaceValidationUI(form) {
form.addEventListener("invalid", function(event) {
event.preventDefault();
}, true);
form.addEventListener("submit", function(event) {
if (!this.checkValidity()) {
event.preventDefault();
}
},true);
//此處寫代碼
var afterB = document.getElementById(‘forms‘);
afterB.addEventListener(‘click‘ , function(event){

var inValidAll = form.querySelectorAll(‘:invalid‘), //擷取所有不符合驗證的資訊
errorAll = form.querySelectorAll(‘.error-messages‘), //擷取所有錯誤的資訊
after;
for(var i = 0;i<inValidAll.length;i++){
after = inValidAll[i].parentNode;
afterB.insertAdjacentHTML(‘afterbegin‘,‘<ul class="error-messages"><li>使用者名稱:‘+inValidAll[i].validationMessage+‘</li></ul>‘);
}
if (inValidAll.length > 0) {
inValidAll[0].focus();
}
for(var i = 0;i<errorAll.length;i++){
errorAll[i].parentNode.removeChild(errorAll[i])
}


})
}
var forms = document.getElementById("forms");
replaceValidationUI(forms);
</script>
</body>

</html>

h5內建表單預設氣泡修改

相關文章

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。