H5 self-brought form default bubble modification

Source: Internet
Author: User

Tags: 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" > User 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= "commit" >
</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);
Write code here
var afterb = document.getElementById (' Forms ');
Afterb.addeventlistener (' click ', Function (event) {

var invalidall = Form.queryselectorall (': Invalid '),//Get all non-conforming information
Errorall = Form.queryselectorall ('. Error-messages '),//Get all the wrong information
After
for (var i = 0;i<invalidall.length;i++) {
after = Invalidall[i].parentnode;
afterb.insertadjacenthtml (' Afterbegin ', ' <ul class= ' error-messages ' ><li> username: ' +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 self-brought form default bubble modification

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: