Js 一些方法(一)

(function ($) {
    var promoter = promoter || {};
    promoter.utils = (function () {
        var controller = "../promoter";
        var pro = function () {
            $("#email").on("blur", function () {
                ValEmail("email");
            });
            $("#application").on("click", function () {
                var email = $("#email").val(); 
                if (!ValEmail("email")) {
                    return false;
                } 
                var arr = $("#email").val().replace(";", ";").split(";");
                var data = { 'email': arr };
                $.ajax({
                    type: "post",
                    url: "promoter/index",
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        if (data.state == "success") {
                            alert("Hello");
                        } else {
                            alert("Faile");
                        }
                    }
                });

            });
        };
        return {
            pro: pro
        };
    }());

    $(function () {
        promoter.utils.pro();
    })
})(jQuery);

function ValEmail(em) {
    if ($("#" + em).val() == "") {
        $("#confirmMsg").html("<font color='red'>请输入审批人邮箱!</font>");
        $("#" + em).focus();
        return false;
    } else {
        var arr = $("#" + em).val().replace(";", ";").split(";");
        for (var i = 0; i < arr.length; i++) {
            if (!arr[i].match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
                $("#confirmMsg").html("<font color='red'>当前'" + arr[i] + "'邮箱格式不正确!请重新输入!</font>");
                $("#" + em).focus();
                return false;
            } else {
                $("#confirmMsg").html("");
            }
        }
        return true;
    }
}

 

posted @ 2015-06-08 16:11  PEPE YU  阅读(300)  评论(0编辑  收藏  举报