$ (function () {//id array to check for empty input boxes var nullcheckarray = new Array ("username", "password", "t
El ");
The ID array of the input box that needs to check the array type var numbercheckarray = new Array ("Age", "Sex", "tel");
$ ("#submit"). Click (function () {//Check for empty checknull (Nullcheckarray);
Check the number type CheckNumber (Numbercheckarray);
Submit Data Userinfopost (/user/add.do);
}); Check if the input box is an empty function checknull (idlist) {if (idlist!= null && idlist.length > 0) {for (VA
R i = 0;i < idlist.length;i++) {var elem = $ ("#" +idlist[i]);
var val = elem.val ();
if ($.trim (val) = "") {alert (Elem.prev (). text+ "cannot be empty!");
return false;
} return true;
}else{return false; }//Listen for input box input type function CheckNumber (idlist{if (idlist!= null && idlist.length > 0) {for (var i = 0;i < idlist.length;i++) {
var Elem = $ ("#" +idlist[i]);
Loss of focus event Elem.blur (function () {var val = elem.val ();
if (!$.isnumeric (val)) {alert (elem.prev.text+ "is a numeric type");
return false;
}
});
return true;
}else{return false;
The value function V (ID) {return $.trim ($ ("#" +id) of an INPUT element is obtained by ID. Val ());
}//Submit user Information function Userinfopost (URL) {//value var username = V ("username");
var password = V ("password");
var age = V (' age ');
var sex = V ("Sex");
var tel = V ("tel"); Package JS Object var userInfo = {"username": username, "password": Password, "age" : Age, "Sex ": Sex," tel ": Tel,}; Submit $.ajax ({type: Post), Url:url, Data:userinfo, success:
function (data) {//Receive server return value alert (data); Set the text box not editable $ (". User-info Input[type=text]"). each (function () {$ (this). attr ("ReadOnly", "readonl
Y ");
$ (this). attr ("Disabled", "disabled");
});
Displays a div $ ("#div1"). CSS ("Display", "block");
Hides a div $ ("#div2"). CSS ("display", "none");
}
}); }
});