init
This commit is contained in:
67
Html-practice/jQuery/01-jQuery-表单验证.html
Normal file
67
Html-practice/jQuery/01-jQuery-表单验证.html
Normal file
@@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||
<script src="./js/FormValidation.js"></script>
|
||||
<link href="./css/FormValidation.css" rel="stylesheet" type="text/css"/>
|
||||
<title>jQuery-表单验证</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div class="main">
|
||||
<form action="form">
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<a class="singup">jQuery-表单验证</a>
|
||||
|
||||
<div class="inputBox">
|
||||
<input type="text" required="required" class="Username">
|
||||
<span class="info1">Username</span>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="inputBox1">
|
||||
<input type="text" required="required" class="Email">
|
||||
|
||||
<span class="info2">Email</span>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="inputBox">
|
||||
<input type="password" required="required" class="Password">
|
||||
|
||||
<span class="info3">Password</span>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<button class="enter">Enter</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
</body>
|
||||
<script>
|
||||
$(function(){
|
||||
$('.Username').blur(function () {
|
||||
$('.Username').tooltip('userName');
|
||||
})
|
||||
$('.Email').blur(function () {
|
||||
$('.Email').tooltip('email');
|
||||
})
|
||||
$('.Password').blur(function () {
|
||||
$('.Password').tooltip('password');
|
||||
})
|
||||
|
||||
})
|
||||
</script>
|
||||
|
||||
</html>
|
116
Html-practice/jQuery/css/FormValidation.css
Normal file
116
Html-practice/jQuery/css/FormValidation.css
Normal file
@@ -0,0 +1,116 @@
|
||||
.main{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.singup {
|
||||
color: #000;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 2px;
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
font-size: x-large;
|
||||
margin-top: 1.5em;
|
||||
}
|
||||
|
||||
.card {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 350px;
|
||||
width: 300px;
|
||||
flex-direction: column;
|
||||
gap: 35px;
|
||||
border-radius: 15px;
|
||||
background: #e3e3e3;
|
||||
box-shadow: 16px 16px 32px #c8c8c8,
|
||||
-16px -16px 32px #fefefe;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.inputBox,
|
||||
.inputBox1 {
|
||||
position: relative;
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
.inputBox input,
|
||||
.inputBox1 input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
outline: none;
|
||||
border: none;
|
||||
color: #000;
|
||||
font-size: 1em;
|
||||
background: transparent;
|
||||
border-left: 2px solid #000;
|
||||
border-bottom: 2px solid #000;
|
||||
transition: 0.1s;
|
||||
border-bottom-left-radius: 8px;
|
||||
}
|
||||
|
||||
.inputBox span,
|
||||
.inputBox1 span {
|
||||
margin-top: 5px;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
transform: translateY(-4px);
|
||||
margin-left: 10px;
|
||||
padding: 10px;
|
||||
pointer-events: none;
|
||||
font-size: 12px;
|
||||
color: #000;
|
||||
text-transform: uppercase;
|
||||
transition: 0.5s;
|
||||
letter-spacing: 3px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.inputBox input:valid~span,
|
||||
.inputBox input:focus~span {
|
||||
transform: translateX(113px) translateY(-15px);
|
||||
font-size: 0.8em;
|
||||
padding: 5px 10px;
|
||||
background: #000;
|
||||
letter-spacing: 0.2em;
|
||||
color: #fff;
|
||||
border: 2px;
|
||||
}
|
||||
|
||||
.inputBox1 input:valid~span,
|
||||
.inputBox1 input:focus~span {
|
||||
transform: translateX(156px) translateY(-15px);
|
||||
font-size: 0.8em;
|
||||
padding: 5px 10px;
|
||||
background: #000;
|
||||
letter-spacing: 0.2em;
|
||||
color: #fff;
|
||||
border: 2px;
|
||||
}
|
||||
|
||||
.inputBox input:valid,
|
||||
.inputBox input:focus,
|
||||
.inputBox1 input:valid,
|
||||
.inputBox1 input:focus {
|
||||
border: 2px solid #000;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.enter {
|
||||
height: 45px;
|
||||
width: 100px;
|
||||
border-radius: 5px;
|
||||
border: 2px solid #000;
|
||||
cursor: pointer;
|
||||
background-color: transparent;
|
||||
transition: 0.5s;
|
||||
text-transform: uppercase;
|
||||
font-size: 10px;
|
||||
letter-spacing: 2px;
|
||||
margin-bottom: 3em;
|
||||
}
|
||||
|
||||
.enter:hover {
|
||||
background-color: rgb(0, 0, 0);
|
||||
color: white;
|
||||
}
|
87
Html-practice/jQuery/js/FormValidation.js
Normal file
87
Html-practice/jQuery/js/FormValidation.js
Normal file
@@ -0,0 +1,87 @@
|
||||
;(function ($) {
|
||||
|
||||
var methods = {
|
||||
//用户名验证
|
||||
userName : function() {
|
||||
var success = "success";
|
||||
var error = "Error";
|
||||
var info = "UserName";
|
||||
//这些方法里面的this指针已经被替换为了$(this)
|
||||
var reg = /^[a-zA-Z0-9\_\+\-\&\$\*]{6,10}$/;
|
||||
if (this.val()==''){
|
||||
// $(".info1").css('color','#000');
|
||||
$(".info1").show().html(info);
|
||||
return;
|
||||
}
|
||||
else if (this.val().match(reg)) {
|
||||
$(".info1").css('color','green');
|
||||
// $(".info1").css('background','#fff');
|
||||
$(".info1").show().html(success);
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
$(".info1").css('color','red');
|
||||
$(".info1").show().html(error);
|
||||
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
// 密码验证
|
||||
password : function( ) {
|
||||
var success = "success";
|
||||
var error = "Error";
|
||||
var info = "Password";
|
||||
var reg = /^[a-zA-Z0-9\_\-]{8,10}$/;
|
||||
if (this.val()==''){
|
||||
// $(".info1").css('color','#000');
|
||||
$(".info3").show().html(info);
|
||||
return;
|
||||
}
|
||||
else if (this.val().match(reg)) {
|
||||
$(".info3").css('color','green');
|
||||
$(".info3").show().html(success);
|
||||
}
|
||||
else {
|
||||
$(".info3").css('color','red');
|
||||
$(".info3").show().html(error);
|
||||
}
|
||||
},
|
||||
//邮箱验证
|
||||
email : function( ) {
|
||||
var success = "success";
|
||||
var error = "Error";
|
||||
var info = "Email";
|
||||
var reg = /^\w+@\w+(.[a-zA-Z]{2,3}){1,2}$/;
|
||||
if (this.val()==''){
|
||||
// $(".info1").css('color','#000');
|
||||
$(".info2").show().html(info);
|
||||
return;
|
||||
}
|
||||
else if (this.val().match(reg)) {
|
||||
$(".info2").css('color','green');
|
||||
$(".info2").show().html(success);
|
||||
}
|
||||
else {
|
||||
$(".info2").css('color','red');
|
||||
$(".info2").show().html(error);
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
$.fn.tooltip = function( method ) {
|
||||
|
||||
// Method calling logic
|
||||
if ( methods[method] ) {
|
||||
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
||||
} else if ( typeof method === 'object' || ! method ) {
|
||||
return methods.init.apply( this, arguments );
|
||||
} else {
|
||||
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
})(jQuery);
|
Reference in New Issue
Block a user