Read JavaScript for a few days, such as object-oriented and basic knowledge of JavaScript, because I write PHP, but also written in Java, so I want to write JavaScript code can also use the object-oriented thinking,
Toss the whole day of JS inheritance and encapsulation, so that I have to eat lunch is thinking about the problem, how the JavaScript code can be so loose? See is going to work, overtime to now do not know how to get such a JS code template, think of every module in the future to write this. The various functional objects are extracted, such as validated, language packs.
Okay, no more nonsense, rookie one, the code is not staring is not complete, Master mercy pointing:
reg.html file:
Reg.js file: $ (function () {var Reg = {regEx: {account:/^\w{5,8}$/, PWD:/^\d{5 , 15}$/, VERIFY:/^\d{4}$/}, Node: {account: $ (' #account '), PWD: $ (' #password '), verify: $ (' #verify '), RegForm: $ (' #regForm ')} , Lang: {account: ' {$Think. Lang.reg_account_tip} ', PWD: ' {$Think. lang.reg_pwd_ti P} ', VERIFY: ' {$Think. Lang.reg_verify_tip} ', Check_verify_url: ' {: U (' home/user/checkverify ') } ", Verify_url:" {: U (' home/user/verify ', ' ', ')} '}, server: {checkver Ify:function (Val, callback) {$.post (Reg.lang.CHECK_VERIFY_URL, {verify:val}, callback, ' JSON ') ; }}, Validator: {account:function (val, tip) {var result = Fal Se if (! Reg.regEx.ACCOUNT.test (val)) {Reg.ui.showTip (tip, Reg.lang.ACCOUNT); } else {result = true; Reg.ui.hideTip (TIP); } return result; }, Pwd:function (val, tip) {var result = false; if (! Reg.regEx.PWD.test (val)) {Reg.ui.showTip (tip, Reg.lang.PWD); } else {result = true; Reg.ui.hideTip (TIP); } return result; }, Verify:function (Val, Tip, callback) {var result = false; if (! Reg.regEx.VERIFY.test (val)) {Reg.ui.showTip (tip, Reg.lang.VERIFY); } else {Reg.server.checkVerify (val, function (data){if (data.status) {if (typeof callback = = = ' function ') { Callback (); } Reg.ui.hideTip (TIP); } else {Reg.ui.showTip (tip, Reg.lang.VERIFY); } } ); } return result; }}, UI: {showtip:function (obj, msg) {$ (obj). Slidedown (' SL Ow '). Find (' span '). HTML (msg); }, Hidetip:function (obj) {$ (obj). Slideup (). Find (' span '). HTML ('); }}, Event: {accountkeyup:function (e) {var self = $ (thi s); SetTimeout (function () {Reg.validator.account (sElf.val (), '. Js-account_alert '); }, 1000); }, Accountblur:function (e) {var self = $ (this); Reg.validator.account (Self.val (), '. Js-account_alert '); }, Passwordkeyup:function (e) {var = $ (this); SetTimeout (function () {Reg.validator.pwd (That.val (), '. Js-pwd_alert '); }, 1000); }, Passwordblur:function (e) {var self = $ (this); Reg.validator.pwd (Self.val (), '. Js-pwd_alert '); }, Verifyblur:function (e) {Reg.validator.verify ($ (this). Val (), '. Js-verify_alert ' ); }, Changeverifyclick:function () {var src = Reg.lang.VERIFY_URL + '/' + new Date (). GE Ttime (); $ (this). attr (' sRC ', SRC); }, Regsubmitbtnclick:function () {Reg.validator.account (Reg.node.account.val (), '. js- Account_alert ') && Reg.validator.pwd (Reg.node.pwd.val (), '. Js-pwd_alert ') && ; Reg.validator.verify (Reg.node.verify.val (), '. Js-verify_alert ', function () {Reg.node.reg Form.submit (); } ); }}, Util: {upfirstletter:function (word) {var reg =/\b (\w) |\ S (\w)/g; Word = Word.tolowercase (); Return Word.replace (Reg, function (m) {return m.touppercase (); } ); }}, Initializer:function () {var node = $ (' [methods] '); Node.each (function () {var = $ (This), methods = SelF.attr (' methods '); if (methods) {var _methods = methods.split (', '); for (var i = 0, len = _methods.length; i < Len; i++) {var method = _methods[i]; if (method) {var func = self.attr (' id ') + Reg.util.upFirstLetter (m Ethod); Console.log (func); Self.on (method, Reg.event[func]); } } } } ); } }; Reg.initializer (); } );
Back-end programmer writes the front-end JS code template