格式化代码

This commit is contained in:
2023-05-01 22:22:17 +08:00
parent 5ea2a40ec4
commit 295f24b49b
4 changed files with 148 additions and 168 deletions

View File

@@ -1,96 +1,91 @@
;(function ($) {
;
(function ($) {
var methods = {
//用户名验证
userName : function() {
userName: function () {
var success = "success";
var error = "Error";
var info = "UserName";
//这些方法里面的this指针已经被替换为了$(this)
var reg = /^[a-zA-Z0-9\_\+\-\&\$\*]{6,10}$/;
if (this.val()==''){
if (this.val() == '') {
// $(".info1").css('color','#000');
$(".info1").show().html(info);
return false;
} else if (this.val().match(reg)) {
$(".info1").css('color', 'green');
// $(".info1").css('background','#fff');
$(".info1").show().html(success);
return true;
} else {
$(".info1").css('color', 'red');
$(".info1").show().html(error);
return false;
}
else if (this.val().match(reg)) {
$(".info1").css('color','green');
// $(".info1").css('background','#fff');
$(".info1").show().html(success);
return true;
}
else {
$(".info1").css('color','red');
$(".info1").show().html(error);
return false;
}
},
// 密码验证
password : function( ) {
password: function () {
var success = "success";
var error = "Error";
var info = "Password";
var reg = /^[a-zA-Z0-9\_\-]{8,10}$/;
if (this.val()==''){
var reg = /^[a-zA-Z0-9\_\-]{8,10}$/;
if (this.val() == '') {
// $(".info1").css('color','#000');
$(".info3").show().html(info);
return false;
}
else if (this.val().match(reg)) {
$(".info3").css('color','green');
} else if (this.val().match(reg)) {
$(".info3").css('color', 'green');
$(".info3").show().html(success);
return true;
}
else {
$(".info3").css('color','red');
} else {
$(".info3").css('color', 'red');
$(".info3").show().html(error);
return false;
}
},
//邮箱验证
email : function( ) {
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()==''){
var reg = /^\w+@\w+(.[a-zA-Z]{2,3}){1,2}$/;
if (this.val() == '') {
// $(".info1").css('color','#000');
$(".info2").show().html(info);
return false;
}
else if (this.val().match(reg)) {
$(".info2").css('color','green');
} else if (this.val().match(reg)) {
$(".info2").css('color', 'green');
$(".info2").show().html(success);
return true;
}
else {
$(".info2").css('color','red');
$(".info2").show().html(error);
return false;
} else {
$(".info2").css('color', 'red');
$(".info2").show().html(error);
return false;
}
}
};
$.fn.tooltip = function( method ) {
$.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 );
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' );
}
$.error('Method ' + method + ' does not exist on jQuery.tooltip');
}
};
})(jQuery);