github.com/jincm/wesharechain@v0.0.0-20210122032815-1537409ce26a/app/script/availdate-v1.0.2.js (about) 1 /*! 2 @Name:availdate-v1.0.2.js 3 @Version:1.0.2 4 @Author:新生帝 5 @Date:2015-11-06 6 @Copyright:中山赢友网络科技有限公司 7 @官网:http://www.winu.net 8 @License:Apache v2 License 9 @Describe:为APICloud表单验证而生,但不仅仅限于此! 10 @QQ交流群:18863883 11 @教程:http://community.apicloud.com/bbs/forum.php?mod=viewthread&tid=17310&extra=page%3D1 12 */ 13 14 ; !function (win) { 15 "use strict"; 16 17 var doc = document, query = 'querySelectorAll', clsEle = 'getElementsByClassName', S = function (s) { 18 return doc[query](s); 19 }; 20 21 var initObj = { 22 tag: [ 23 "input", 24 "select", 25 "textarea" 26 ], 27 noInputTextFormType: [ 28 "radio", 29 "checkbox" 30 ], 31 otherInputFormType: [ 32 "button", 33 "image", 34 "submit", 35 "reset" 36 ], 37 tagAttr: [ 38 "data-rule", 39 "data-nullmsg", 40 "data-errmsg", 41 "data-sucmsg", 42 "data-sync", 43 "data-haved" 44 ], 45 rules: { 46 // 检测是否有输入,可以输入任何字符,不留空即可通过验证; 47 "*": /^[\w\W]+$/, 48 // 检测是否为6到16位任意字符; 49 "*6-16": /^[\w\W]{6,16}$/, 50 // 数字类型; 51 "n": /^\d+$/, 52 // 6到16位数字; 53 "n6-16": /^\d{6,16}$/, 54 // 字符串类型; 55 "s": /^[\u4E00-\u9FA5\uf900-\ufa2d\w\.\s]+$/, 56 // 6到18位字符串; 57 "s6-18": /^[\u4E00-\u9FA5\uf900-\ufa2d\w\.\s]{6,18}$/, 58 // 验证是否为邮政编码; 59 "p": /^[0-9]{6}$/, 60 // 手机号码格式; 61 "m": /^13[0-9]{9}$|14[0-9]{9}|15[0-9]{9}$|18[0-9]{9}$|17[0-9]{9}$/, 62 // email格式; 63 "e": /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, 64 // 验证字符串是否为网址。 65 "url": /^(\w+:\/\/)?\w+(\.\w+)+.*$/, 66 // 日期格式 67 "date": /^(?:(?:1[6-9]|[2-9][0-9])[0-9]{2}([-/.]?)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:(?:1[6-9]|[2-9][0-9])(?:0[48]|[2468][048]|[13579][26])|(?:16|[2468][048]|[3579][26])00)([-/.]?)0?2\2(?:29))(\s+([01][0-9]:|2[0-3]:)?[0-5][0-9]:[0-5][0-9])?$/, 68 //匹配中文字符; 69 "zh": /^[\u4e00-\u9fa5]+$/, 70 //匹配双字节字符; 71 "dword": /^[^\x00-\xff]+$/, 72 // 货币类型 73 "money": /^(([0-9]|([1-9][0-9]{0,9}))((\.[0-9]{1,2})?))$/, 74 //匹配ipv4地址; 75 "ipv4": /^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$/, 76 // 匹配ipv6地址; 77 "ipv6": /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/, 78 //数值型; 79 "num": /^(\d+[\s,]*)+\.?\d*$/, 80 //QQ号码; 81 "qq": /^[1-9][0-9]{4,}$/, 82 // 身份证 83 "idcard": /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, 84 // 时间格式 例如:10:57:10 85 "time": /^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/, 86 // 固话 87 "t": /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/, 88 // 手机或者固话 89 "tm": /((15)\d{9})|((13)\d{9})|((18)\d{9})|(0[1-9]{2,3}\-?[1-9]{6,7})/i, 90 // 判断是否是视频文件 91 "video": /(.*)\.(rm|rmvb|wmv|avi|mp4|3gp|mkv)$/, 92 // 判断是否是flash文件 93 "flash": /(.*)\.(swf|fla|flv)$/, 94 // 判断是否是mp3文件 95 "mp3": /(.*)\.(mp3)$/, 96 // 判断是否是文档文件 97 "doc": /(.*)\.(doc|xls|docx|xlsx|pdf)$/, 98 // 判断是否是图片文件 99 "img": /(.*)\.(jpg|gif|ico|jpeg|png)$/, 100 // 判断是否是压缩包文件 101 "zip": /(.*)\.(rar|zip|7zip|tgz)$/, 102 // 判断是否一个md5字符串 103 "md5": /^([a-fA-F0-9]{32})$/, 104 // 判断是否是ascii码 105 "ascii": /^[\x00-\xFF]+$/, 106 // 判断是否是十六进制颜色值 107 "color": /^#[0-9a-fA-F]{6}$/, 108 // 判断是否全部是小写字母 109 "ens": /^[a-z]+$/, 110 // 判断是否是全部大写字母 111 "enb": /^[A-Z]+$/, 112 // 判断是否是正常的年龄 113 "age": /^[1-99]?\d*$/, 114 // 判断是否是中文名称 115 "cname": /^[\u0391-\uFFE5]{2,15}$/, 116 // 判断是否是英文名称 117 "ename": /^[A-Za-z]{1,161}$/, 118 // 判断是否是正数 119 "pn": /^[+]?\d+(\.\d+)?$/, 120 // 判断是否是负数 121 "upn": /^-[1-9]\d*\.\d*|-0\.\d*[1-9]\d*$/ 122 }, 123 tip: { 124 "*": "不能为空!", 125 "*6-16": "请填写$1到$2位任意字符!", 126 "n": "请填写数字!", 127 "n6-16": "请填写$1到$2位数字!", 128 "s": "不能输入特殊字符!", 129 "s6-16": "请填写$1到$2位字符!", 130 "p": "请填写邮政编码!", 131 "m": "请填写手机号码!", 132 "e": "邮箱地址格式不对!", 133 "url": "请填写网址!", 134 "date": "请填写日期!", 135 "zh": "请填写中文!", 136 "dword": "请填写双字节字符!", 137 "money": "请填写货币值!", 138 "ipv4": "请填写ip地址!", 139 "ipv6": "请填写IPv6地址!", 140 "num": "请填写数值!", 141 "qq": "请填写QQ号码!", 142 "idcard": "请填写身份证号码", 143 "time": "请输入时间格式", 144 "t": "请输入固话", 145 "tm": "请输入手机或固话", 146 "video": "请输入视频文件", 147 "flash": "请输入flash文件", 148 "mp3": "请输入mp3文件", 149 "doc": "请输入文档文件", 150 "img": "请输入图片格式文件", 151 "zip": "请输入压缩包格式文件", 152 "md5": "请输入md5码字符串", 153 "ascii": "请输入ascii码字符串", 154 "color": "请输入十六进制颜色字符串", 155 "ens": "请输入纯小写字母", 156 "enb": "请输入纯大写字母", 157 "age": "请输入正确的年龄", 158 "cname": "请输入正确的中文名称", 159 "ename": "请输入正确的英文名称", 160 "pn": "请输入正确的正数", 161 "upn": "请输入正确的负数" 162 } 163 }, ruleDoms = []; 164 165 win.base = { 166 extend: function (config, obj) { 167 var newobj = config; 168 for (var i in obj) { 169 newobj[i] = obj[i]; 170 } 171 return newobj; 172 }, 173 isFormEle: function (nodeName) { 174 return initObj.tag.indexOf(nodeName) > -1; 175 }, 176 getAttribute: function (node, attr) { 177 return node.getAttribute(attr) == null ? false : node.getAttribute(attr) 178 }, 179 // 判断是否是可以输入的表单元素 180 isInputForm: function (node) { 181 var nodeType = "text"; 182 if (base.getAttribute(node, "type")) { 183 nodeType = base.getAttribute(node, "type"); 184 } 185 return initObj.noInputTextFormType.indexOf(nodeType) == -1 && initObj.otherInputFormType.indexOf(nodeType) == -1; 186 }, 187 isRadioOrCheckBox: function (node) { 188 var nodeType = "text"; 189 if (base.getAttribute(node, "type")) { 190 nodeType = base.getAttribute(node, "type"); 191 } 192 return initObj.noInputTextFormType.indexOf(nodeType) > -1; 193 }, 194 isSelectList: function (node) { 195 return node.nodeName.toLocaleLowerCase() == "select"; 196 }, 197 isRadio: function (node) { 198 var nodeType = "text"; 199 if (base.getAttribute(node, "type")) { 200 nodeType = base.getAttribute(node, "type"); 201 } 202 return nodeType.toLocaleLowerCase() == "radio"; 203 }, 204 isCheckbox: function (node) { 205 var nodeType = "text"; 206 if (base.getAttribute(node, "type")) { 207 nodeType = base.getAttribute(node, "type"); 208 } 209 return nodeType.toLocaleLowerCase() == "checkbox"; 210 }, 211 trim: function (str) { 212 return str.replace(/^\s+|\s+$/g, "") 213 }, 214 getAllChildrens: function (obj) { 215 var cns = obj.childNodes; 216 if (cns.length == 0) { 217 } 218 else { 219 for (var i = 0; i < cns.length; i++) { 220 base.getAllChildrens(cns[i]); 221 ruleDoms.push(cns[i]); 222 } 223 } 224 } 225 }; 226 227 // 默认配置 228 var config = { 229 area: "body", 230 btn: "#winunet", 231 startCheck: function () { 232 }, 233 singleSuccess: function (e, msg) { 234 }, 235 singleError: function (e, msg) { 236 alert(msg); 237 }, 238 endSuccess: function (data) { 239 alert("全部验证成功啦!" + JSON.stringify(data)); 240 } 241 }; 242 243 var Winu = function (options) { 244 var that = this; 245 246 that.config = base.extend(config, options); 247 that.isSuccess = true; 248 that.ready(); 249 }; 250 251 // 判断是否具有预定义的认证规则 252 Winu.prototype.isHasRule = function (node) { 253 var attrs = node.attributes; 254 var flag = false; 255 256 for (var i = 0; i < attrs.length; i++) { 257 if (initObj.tagAttr.indexOf(attrs[i].name) > -1) { 258 return flag = true; 259 } 260 else { 261 continue; 262 } 263 } 264 return flag; 265 } 266 267 // 获取验证区域下的所有需要验证表单元素 268 Winu.prototype.getFormNodes = function () { 269 var that = this, areaFormEles = []; 270 271 var _area = S(that.config.area); 272 if (_area.length == 0) { 273 console.error("验证区域必须是页面上的元素,可以是标签名,class或者id选择器!"); 274 return; 275 } 276 if (_area.length > 1) { 277 console.warn("页面具有相同的验证区域,默认只对第一个验证区域有用!"); 278 } 279 280 ruleDoms = []; 281 base.getAllChildrens(_area[0]); 282 283 for (var i = 0; i < ruleDoms.length; i++) { 284 if (base.isFormEle(ruleDoms[i].nodeName.toLocaleLowerCase())) { 285 if (that.isHasRule(ruleDoms[i])) { 286 areaFormEles.push(ruleDoms[i]); 287 } 288 } 289 } 290 return areaFormEles; 291 }; 292 293 // 具有可输入的验证 294 Winu.prototype.inputArea = function (node) { 295 var that = this; 296 297 var _rule = base.getAttribute(node, initObj.tagAttr[0]); 298 var _nullmsg = base.getAttribute(node, initObj.tagAttr[1]); 299 var _errmsg = base.getAttribute(node, initObj.tagAttr[2]); 300 var _sucmsgg = base.getAttribute(node, initObj.tagAttr[3]); 301 var _sync = base.getAttribute(node, initObj.tagAttr[4]); 302 var _haved = base.getAttribute(node, initObj.tagAttr[5]); 303 304 var _value = node.value; 305 var _name = base.getAttribute(node, "name"); 306 307 // 判断是否有同步属性 308 if (_sync && _sync != "") { 309 var _syncNode = S(node.nodeName.toLocaleLowerCase() + "[name='" + _sync + "']"); 310 if (_syncNode.length > 0) { 311 _rule = base.getAttribute(_syncNode[0], initObj.tagAttr[0]); 312 313 _nullmsg = _nullmsg == false ? base.getAttribute(_syncNode[0], initObj.tagAttr[1]) : _nullmsg; 314 _errmsg = _errmsg == false ? base.getAttribute(_syncNode[0], initObj.tagAttr[2]) : _errmsg; 315 _sucmsgg = _sucmsgg == false ? base.getAttribute(_syncNode[0], initObj.tagAttr[3]) : _sucmsgg; 316 _sync = _sync == false ? base.getAttribute(_syncNode[0], initObj.tagAttr[4]) : _sync; 317 _haved = _haved == false ? base.getAttribute(_syncNode[0], initObj.tagAttr[5]) : _haved; 318 319 var _syncValue = _syncNode[0].value; 320 321 // 判断两次值是否一样 322 if (base.trim(_value) == "") { 323 that.config.singleError(node, _nullmsg == false ? initObj.tip[_rule] : _nullmsg); 324 node.focus(); 325 that.isSuccess = that.isSuccess && false; 326 return; 327 } 328 else { 329 if (_syncValue != _value) { 330 that.config.singleError(node, _errmsg == false ? "两次输入值不一样" : _errmsg); 331 node.focus(); 332 that.isSuccess = that.isSuccess && false; 333 return; 334 } 335 else { 336 that.config.singleSuccess(node, _sucmsgg == false ? "验证成功" : _sucmsgg); 337 that.isSuccess = that.isSuccess || true; 338 } 339 } 340 341 } 342 } 343 344 345 if (_rule) { 346 // 1、判断是否是预定义正则表达式 347 if (initObj.rules[_rule]) { 348 if (base.trim(_value) == "") { 349 // 判断是否有 data-haved属性 350 if (_haved == false) { 351 that.config.singleError(node, _nullmsg == false ? initObj.tip[_rule] : _nullmsg); 352 node.focus(); 353 that.isSuccess = that.isSuccess && false; 354 return; 355 } 356 else { 357 that.config.singleSuccess(node, _sucmsgg == false ? "验证成功" : _sucmsgg); 358 that.isSuccess = that.isSuccess || true; 359 } 360 } else { 361 if (!initObj.rules[_rule].test(_value)) { 362 that.config.singleError(node, _errmsg == false ? "验证失败" : _errmsg); 363 node.focus(); 364 that.isSuccess = that.isSuccess && false; 365 return; 366 } 367 else { 368 that.config.singleSuccess(node, _sucmsgg == false ? "验证成功" : _sucmsgg); 369 that.isSuccess = that.isSuccess || true; 370 } 371 } 372 } 373 else { 374 if (base.trim(_value) == "") { 375 // 判断是否有 data-haved属性 376 if (_haved == false) { 377 that.config.singleError(node, _nullmsg == false ? initObj.tip[_rule] : _nullmsg); 378 node.focus(); 379 that.isSuccess = that.isSuccess && false; 380 return; 381 } 382 else { 383 that.config.singleSuccess(node, _sucmsgg == false ? "验证成功" : _sucmsgg); 384 that.isSuccess = that.isSuccess || true; 385 } 386 } else { 387 // 2、判断是否和预定义匹配符匹配 388 if (/^.[0-9]+\-[0-9]+$/.test(_rule)) { 389 var _f = _rule.substr(0, 1); 390 var _temp = _rule.substr(1, _rule.length - 1); 391 var _range = _temp.split("-"); 392 if (parseInt(_range[0]) < parseInt(_range[1])) { 393 394 if (initObj.rules[_f]) { 395 var _r = initObj.rules[_f].toString().replace("$/", "{" + _range[0] + "," + _range[1] + "}$/").replace("+", ""); 396 var _rex = eval(_r); 397 if (!_rex.test(_value)) { 398 that.config.singleError(node, _errmsg == false ? (initObj.tip[_f + "6-16"].replace("$1", _range[0]).replace("$2", _range[1])) : _errmsg); 399 node.focus(); 400 that.isSuccess = that.isSuccess && false; 401 return; 402 } 403 else { 404 that.config.singleSuccess(node, _sucmsgg == false ? "验证成功" : _sucmsgg); 405 that.isSuccess = that.isSuccess || true; 406 } 407 } 408 else { 409 console.warn("没有以" + _f + "开头的标识符!已跳过验证!"); 410 that.isSuccess = that.isSuccess || true; 411 } 412 } 413 else { 414 console.warn("规则标识符数字范围前者应小于后者"); 415 that.isSuccess = that.isSuccess && true; 416 } 417 } 418 else { 419 var _rex = eval(_rule); 420 if (!_rex.test(_value)) { 421 that.config.singleError(node, _errmsg == false ? "验证失败" : _errmsg); 422 node.focus(); 423 that.isSuccess = that.isSuccess && false; 424 return; 425 } 426 else { 427 that.config.singleSuccess(node, _sucmsgg == false ? "验证成功" : _sucmsgg); 428 that.isSuccess = that.isSuccess || true; 429 } 430 } 431 } 432 } 433 } 434 }; 435 436 // 单选按钮,复选按钮的验证 437 Winu.prototype.radioOrCheckbox = function (node) { 438 var that = this; 439 440 var _rule = base.getAttribute(node, initObj.tagAttr[0]); 441 var _nullmsg = base.getAttribute(node, initObj.tagAttr[1]); 442 var _errmsg = base.getAttribute(node, initObj.tagAttr[2]); 443 var _sucmsgg = base.getAttribute(node, initObj.tagAttr[3]); 444 445 var _value = node.value; 446 var _name = base.getAttribute(node, "name"); 447 var _type = base.getAttribute(node, "type"); 448 449 if (_rule && _rule == "*") { 450 if (_name) { 451 var tag = false; 452 var radios = S("input[name='" + _name + "'][type='" + _type + "']"); 453 for (var radio in radios) { 454 if (radios[radio].checked) { 455 tag = true; 456 break; 457 } 458 } 459 if (tag) { 460 that.config.singleSuccess(node, _sucmsgg == false ? "验证成功" : _sucmsgg); 461 that.isSuccess = that.isSuccess || true; 462 } 463 else { 464 that.config.singleError(node, _nullmsg == false ? "必须选择!" : _nullmsg); 465 node.focus(); 466 that.isSuccess = that.isSuccess && false; 467 return; 468 } 469 } 470 else { 471 console.warn("radio的name属性不能为空!"); 472 that.isSuccess = that.isSuccess && true; 473 } 474 } 475 else { 476 console.warn("规则标识符不正确,应使用 * 符号"); 477 that.isSuccess = that.isSuccess && true; 478 } 479 }; 480 481 // 下拉框的验证 482 Winu.prototype.select = function (node) { 483 var that = this; 484 var _rule = base.getAttribute(node, initObj.tagAttr[0]); 485 var _nullmsg = base.getAttribute(node, initObj.tagAttr[1]); 486 var _sucmsgg = base.getAttribute(node, initObj.tagAttr[3]); 487 488 if (_rule && _rule == "*") { 489 if (node.value == "") { 490 that.config.singleError(node, _nullmsg == false ? "必须选择!" : _nullmsg); 491 node.focus(); 492 that.isSuccess = that.isSuccess && false; 493 return; 494 } 495 else { 496 that.config.singleSuccess(node, _sucmsgg == false ? "验证成功" : _sucmsgg); 497 that.isSuccess = that.isSuccess || true; 498 } 499 } 500 else { 501 console.warn("规则标识符不正确,应使用 * 符号"); 502 that.isSuccess = that.isSuccess && true; 503 } 504 }; 505 // 拓展规则 506 Winu.prototype.extRule = function (rule) { 507 var that = this; 508 initObj.rules = base.extend(initObj.rules, rule); 509 } 510 511 // 验证核心方法 512 Winu.prototype.core = function (node) { 513 var that = this; 514 if (base.isInputForm(node) && !base.isRadioOrCheckBox(node) && !base.isSelectList(node)) { 515 that.inputArea(node); 516 } 517 else if (base.isRadioOrCheckBox(node)) { 518 that.radioOrCheckbox(node); 519 } 520 else if (base.isSelectList(node)) { 521 that.select(node); 522 } 523 }; 524 525 Winu.prototype.beginCheck = function (func) { 526 var that = this; 527 528 that.isSuccess = true; 529 that.config.startCheck(); 530 var areaFormEles = that.getFormNodes(); 531 532 var serialData = {}; 533 for (var i = 0; i < areaFormEles.length; i++) { 534 var v = areaFormEles[i].value; 535 var n = areaFormEles[i].name; 536 var t = areaFormEles[i].type; 537 538 // 判断是否是checkbox 539 if (t.toLocaleLowerCase() == "checkbox" || t.toLocaleLowerCase() == "radio") { 540 if (areaFormEles[i].checked) { 541 if (serialData[n] != null && serialData != undefined) { 542 serialData[n] = serialData[n] + "," + v; 543 } 544 else { 545 serialData[n] = v; 546 } 547 } 548 } 549 else { 550 if (serialData[n] != null && serialData != undefined) { 551 serialData[n] = serialData[n] + "," + v; 552 } 553 else { 554 serialData[n] = v; 555 } 556 } 557 558 559 560 if (that.isSuccess) { 561 that.core(areaFormEles[i]); 562 } 563 else { 564 break; 565 } 566 } 567 if (that.isSuccess) { 568 if (typeof func == "function") { 569 func(); 570 } 571 else { 572 that.config.endSuccess(serialData); 573 } 574 } 575 } 576 577 Winu.prototype.ready = function () { 578 var that = this; 579 580 var _btn = S(that.config.btn); 581 if (_btn.length == 0) { 582 console.warn("没有找到触发验证的按钮,请自动调用原型方法执行验证!"); 583 return; 584 } 585 else { 586 _btn[0].addEventListener("click", function (e) { 587 that.beginCheck(); 588 }); 589 } 590 } 591 592 var ac = {}; 593 ac.form = function (options) { 594 var o = new Winu(options || {}); 595 return o; 596 } 597 ac.addRule = function (rule) { 598 Winu.prototype.extRule(rule); 599 } 600 601 win.ac = ac; 602 }(window);