首页 > 代码库 > Jquery 自定义插件写法
Jquery 自定义插件写法
(function ($) { $.SmsHelper = $.SmsHelper || {}; $.extend($.SmsHelper, { yzmnum: 60, AjaxUrl: "/AjaxMethod/CommonSMS.ashx?key=GetSmsCode", GetSmsCodeClick: function (phoneCode, obj) { if (phoneCode == ‘‘) { $.AmHelper.ShowMsg(‘请输入手机号‘); return; } var reg = /^1[358]\d{9}$/; if (!reg.test(phoneCode)) { $.AmHelper.ShowMsg("手机号码格式不正确!"); return; } var objText = $(obj).val(); if (objText == ‘‘) { objText = $(obj).text(); if (objText.indexOf(‘验证码‘) > -1) { $.SmsHelper.GetSmsCodeEx(phoneCode, obj); } } else { if (objText.indexOf(‘验证码‘) > -1) { $.SmsHelper.GetSmsCode(phoneCode, obj); } } }, //获得手机验证码 GetSmsCode: function (mobile, obj) { $(obj).val(‘请稍后...‘ + $.SmsHelper.yzmnum); $(obj).attr("disabled", true); var yzmtime = setInterval(function () { $.SmsHelper.yzmnum--; $(obj).val(‘请稍后...‘ + $.SmsHelper.yzmnum); if ($.SmsHelper.yzmnum == 0) { $(obj).val(‘获取验证码‘); $(obj).attr("disabled", false); clearInterval(yzmtime); $.SmsHelper.yzmnum = 60; } }, 1000); if (mobile != "") { $.ajax({ type: "post", url: $.SmsHelper.AjaxUrl, data: { "Mobile": mobile, "PageType": $.SmsHelper.smsPageType }, async: false, dataType: "json", success: function (msg) { if (msg.returncode == "0") { $.AmHelper.ShowMsg("验证码短信已发送"); } else { $.AmHelper.ShowMsg(msg.message); } }, complete: function (XHR, TS) { XHR = null } }); } else { $.AmHelper.ShowMsg(‘请填写手机号码!‘); } }, GetSmsCodeEx: function (mobile, obj, pageType) { $(obj).text(‘请稍后...‘ + $.SmsHelper.yzmnum); $(obj).attr("disabled", true); var yzmtime = setInterval(function () { $.SmsHelper.yzmnum--; $(obj).text(‘请稍后...‘ + $.SmsHelper.yzmnum); if ($.SmsHelper.yzmnum == 0) { $(obj).text(‘获取验证码‘); $(obj).attr("disabled", false); clearInterval(yzmtime); $.SmsHelper.yzmnum = 60; } }, 1000); if (mobile != "") { $.ajax({ type: "post", url: $.SmsHelper.AjaxUrl, data: { "Mobile": mobile, "PageType": smsPageType }, async: false, dataType: "json", success: function (msg) { if (msg.returncode == "0") { $.AmHelper.ShowMsg("验证码短信已发送"); } else { $.AmHelper.ShowMsg(msg.message); } }, complete: function (XHR, TS) { XHR = null } }); } else { $.AmHelper.ShowMsg(‘请填写手机号码!‘); } } });})(jQuery);
Jquery 自定义插件写法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。