<! DOCTYPE html>
<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>
<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>
H5 self-brought form default bubble modification