input_validator.js
来自「ruby on rails web敏捷开发之路第二版 源代码」· JavaScript 代码 · 共 45 行
JS
45 行
InputValidator = Class.create();Object.extend(InputValidator.prototype, { form: "form", initialize: function (options) { Object.extend(this,options); var temp = $(this.form).action.split("/").slice(0,-1); temp.push("validate"); this.validateAction = temp.join("/"); $A($(this.form).getElementsByTagName("input")).each((function(e) { if (e.type == "text") { var validator = this.validatorForElement(e); if (validator) { Event.observe(e, "blur", validator.bind(this)); } } }).bind(this)); }, validatorForElement: function(e) { return function() { //codecite Ajax.Request new Ajax.Request(this.validateAction, { method: 'get', parameters: e.name + "=" + e.value, onSuccess: (function(req) { this.reportValidation(e, req.responseText); }).bind(this), onFailure: function(req) {alert(req.responseText)}, onException: function(t,e) {alert(e);} }); //codecite Ajax.Request } }, removeOldValidation: function (el) { var sib = el.nextSibling; if (sib && Element.hasClassName(sib, "errorExplanation")) { Element.remove(sib); } }, reportValidation: function(el, resp) { this.removeOldValidation(el); if (resp && (/\S/).test(resp)) { new Insertion.After(el, "<span class='errorExplanation'>" + resp + "</span>"); } }});
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?