日期:2014-05-16  浏览次数:20441 次

Js jquery 一些公用方法
//超出隐藏公用方法
function strOverHidden(str, maxNum, appendStr) {
    var len = str.length;
    var appLen = appendStr.length;
    if (len > maxNum) {
        return str.substr(0, maxNum) + appendStr;
    }
    return str;
}
//异步异常处理
function error(msg) {
    $("body").html("");
    $("body").html(msg.responseText);
}
//字符串非空验证
function isNullOrEmpty(val) {
    return (val == null || val == undefined || val == "");
}

//增加ALERT 框大小
function alertWindowSize(size) {
    $(".regsuccess").closest(".window").css({ "width": size, left: ($(window).width() - size) / 2 })
    .find(".panel-header").css("width", size);
    $(".regsuccess").closest(".window").find(".messager-button").css({ "padding": 10 });
    $(".regsuccess").closest(".window-body").css("width", size - 22);
}
//增加confirm 框大小
function confirmWindowSize(size) {
    $(".consuccess").closest(".window").css({ "width": size, left: ($(window).width() - size) / 2 })
    .find(".panel-header").css("width", size);
    $(".consuccess").closest(".window").find(".messager-button").css({ "padding": 10 });
    $(".consuccess").closest(".window-body").css("width", size - 22);
}

//清空验证状态
function validateStatusClear() {
    $("[name=spanValMesBox]").remove();
    $(".validatebox-invalid").removeClass("validatebox-invalid");
}
function vf() { }

/// <summary>
///  飞动效果
/// </summary>
/// <param name="id">要飞的控件ID</param>
/// <param name="changeIdstr">要飞到的控件ID和要飞的控件ID的区别字符串</param>
///<param name="isAfter">区别字符串是否放在后面</param>
function KaiXuan_fly(id, changeIdstr, isAfter) {
    var thisoff = $("#" + id).offset();
    var flyToObjectId = isAfter ? ("#" + id + changeIdstr) : ("#" + changeIdstr + id);
    var flyId = id + "thisfly";
    if ($("#" + flyId).size() == 0) {
        var flyToObjectOff = $(flyToObjectId).offset();
        var flyObject = $("<div>").attr("id", flyId)
        .css({
            position: "absolute",
            "z-index": 900000,
            left: thisoff.left,
            top: thisoff.top
        });
        flyObject.append($("#" + id).find("img").clone(true));
        $("body").append(flyObject);
        $("#" + flyId).find("img").animate({
            left: flyToObjectOff.left,
            top: flyToObjectOff.top,
            opacity: 0.5,
            width: 10,
            height: 10
        }, 800, function () {
        });
        $("#" + flyId).animate({
            left: flyToObjectOff.left,
            top: flyToObjectOff.top,
            opacity: 0.5,
            width: 10,
            height: 10
        }, 800, function () {
            $(this).remove();
        });

    }
}

$.fn.extend({
    //DOC元素如果高度小于最小值则该元素高度等于这个最小值 www.52mvc.com
    minHeigth: function (minHeigth) {
        var tw = this.height();
        if (tw < minHeigth) {
            this.css({ height: minHeigth })
        }


    },
    watermark: function (watermarkText) {
        this.attr("title", watermarkText);
        this.val(watermarkText);
        this.css({ color: "#666666" });
        this.click(function () {
            var ts = $(this);
            var tsVal = ts.val();
            if (watermarkText == tsVal) {
                ts.val("");
                ts.removeAttr("style");
            }
        })
        this.blur(function () {
            var ts = $(this);