码迷,mamicode.com
首页 > Web开发 > 详细

Jquery 自定义插件写法

时间:2014-11-17 13:53:03      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   sp   div   

bubuko.com,布布扣
(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);
View Code

 

Jquery 自定义插件写法

标签:style   blog   http   io   color   ar   os   sp   div   

原文地址:http://www.cnblogs.com/lindaWei/p/4103292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!