通用代码2

http_path = '';

/**
 * 是否相等
 */
function equals(obj1, obj2) {
    if (obj1 == obj2)
        return true;

    if (typeof (obj1) == "undefined" || obj1 == null
        || typeof (obj1) != "object")
        return false;

    if (typeof (obj2) == "undefined" || obj2 == null
        || typeof (obj2) != "object")
        return false;

    var length1 = 0;
    var length2 = 0;

    for (var ele in obj1) {
        length1++;
    }

    for (var ele in obj2) {
        length2++;
    }

    if (length1 != length2)
        return false;
// 由于该方法会与echarts冲突,所以添加一个对数组的判断,在echarts内部是数组,有bug。
    if (Object.prototype.toString.call(obj1) !== Object.prototype.toString.call(obj2)) {
        return false;
    }
    if (Object.prototype.toString.call(obj1) == '[object Array]') {
        if (obj1.length != obj2.length) {
            return false;
        }
        for (var i = 0; i < obj1.length; i++) {
            if (obj1[i] == obj2[i]) {
                break;
            }
            return false;
        }
        return true;
    }
    if (obj1.constructor == obj2.constructor) {
        for (var ele in obj1) {
            if (typeof (obj1[ele]) == "object") {
                if (!equals(obj1[ele], obj2[ele]))
                    return false;
            } else if (typeof (obj1[ele]) == "function") {
                if ((obj1[ele].toString()) != (obj2[ele].toString()))
                    return false;
            } else if (obj1[ele] != obj2[ele])
                return false;
        }
        return true;
    }

    return false;
}

if (typeof jsAct == 'undefined' || (typeof jsAct != 'undefined' && jsAct != 'index')) {

    /**
     * 是否包含对象
     * @param obj
     * @returns {Boolean}
     */
    Array.prototype.inArray = function (obj) {
        for (i = 0; i < this.length; i++) {
            if (equals(this[i], obj))
                return true;
        }

        return false;
    }
    /**
     * 查找对象在数组中的位置
     * @param obj
     * @returns
     */
    Array.prototype.indexOf = function (obj) {
        for (var i = 0; i < this.length; i++) {
            if (equals(this[i], obj))
                return i;
        }
        return -1;
    }
    /**
     * 方法:removeObject(obj)
     * 功能:根据元素值删除数组元素.
     * 参数:obj
     * 返回:在原数组上修改数组
     */
    Array.prototype.removeObject = function (obj) {
        var index = this.indexOf(obj);
        if (index > -1) {
            this.splice(index, 1);
        }
        return this;
    };
    /**
     * 方法:removeObjectById(id)
     * 功能:根据元素值删除数组元素.
     * 参数:id
     * 返回:在原数组上修改数组
     */
    Array.prototype.removeObjectById = function (id) {
        for (var i = 0; i < this.length; i++) {
            if (this[i].id == id) {
                return this.splice(i, 1);
            }
        }
        return this;
    };
    /**
     * 方法:removeObjectAtIndex(dx)
     * 功能:根据元素位置值删除数组元素.
     * 参数:dx
     * 返回:在原数组上修改数组
     */
    Array.prototype.removeObjectAtIndex = function (dx) {
        if (isNaN(dx) || dx < this.length || dx > this.length) {
            return this;
        }
        return this.splice(dx, 1);
    };
    /**
     * 方法:findObjectById(id)
     * 功能:根据id查找数组元素.
     * 参数:id
     * 返回:数组元素
     */
    Array.prototype.findObjectById = function (id) {
        for (var i = 0; i < this.length; i++) {
            if (this[i].id == id) {
                return this[i];
            }
        }
        return null;
    };
}

/**
 * 删除所有空白
 * @returns
 */
String.prototype.trim = function () {
    return this.replace(/(^\s+)|(\s+$)/g, "");
};

/**
 * 是否为空白
 * @returns {Boolean}
 */
String.prototype.isBlank = function () {
    return this == null || this.trim() == "";
}

/**
 * 删除左边的空白
 *
 * @returns
 */
String.prototype.lTrim = function () {
    return this.replace(/(^\s+)/g, "");
}

/**
 * 删除右边的空白
 *
 * @returns
 */
String.prototype.rTrim = function () {
    return this.replace(/(\s+$)/g, "");
}

/**
 * 是否有效的手机号码
 *
 * @returns
 */
String.prototype.test = function () {
    return (new RegExp(/^([\S^'^‘^’]{6,20})$/)
        .test(this));
}

/**
 * 是否有效的手机号码
 *
 * @returns
 */
String.prototype.isMobileNum = function() {
    return (new RegExp(/^1\d{10}$/)
            .test(this));
}

/**
 * 是否为汉字
 * @returns
 */
String.prototype.isChinese = function () {
    return (new RegExp("[\\u4E00-\\u9FFF]+", "g")
        .test(this));
}

/**
 * 是否有效的邮箱
 *
 * @returns
 */
String.prototype.isEmail = function () {
    return (
        new RegExp(/^([a-zA-Z0-9])+([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+((\.([a-zA-Z0-9_-]){2,3}){1,2})$/).test(this)
    );
}

/**
 * 是否是QQ邮箱
 */
String.prototype.isQQEmail = function () {
    return new RegExp(/^([\s\S]*@qq.com)$/).test(this);
}


/**
 * 是否日期
 *
 * @returns
 */
String.prototype.isDate = function () {
    return (new RegExp(
        /^([1-2]\d{3})[\/|\-](0?[1-9]|10|11|12)[\/|\-]([1-2]?[0-9]|0[1-9]|30|31)$/ig)
        .test(this));
}

/**
 * 替换全部
 */
String.prototype.replaceAll = function (s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
}

/**
 * 克隆(深拷贝)
 *
 * @param obj
 * @returns
 */
function clone(obj) {
    if (typeof (obj) != 'object') {
        return obj;
    }

    var re = {};

    if (obj.constructor == Array) {
        re = [];
    }

    for (var i in obj) {
        re[i] = clone(obj[i]);
    }

    return re;
}

/**
 * 居中显示div
 *
 * @param obj
 */
function showDiv(obj, callback) {
    //获取返回的页面信息,如页面信息拥有登入页面特定代码,则确定登入失效,跳转到登入页面
    var searA = new RegExp("SDBGIOH24HFQ94HT2HSDAF89Q2P");
    if (searA.test(obj.html())) {
        window.location.href = http_path + "/login";
    } else {
        $(obj).show();
    }


    center(obj);

    $(window).scroll(function () {
        center(obj);
    });

    $(window).resize(function () {
        center(obj);
    });
    if ($.isFunction(callback)) {
        callback();
    }
}

function center(obj) {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(obj).height();
    var popupWidth = $(obj).width();
    $(obj).css({
        "position": "absolute",
        "top": (windowHeight - popupHeight) / 2 + $(document).scrollTop(),
        "left": (windowWidth - popupWidth) / 2
    });
}

/**
 * 上传图片
 * @param fileElementId
 * @param imageElementId
 */
function uploadImage(fileElementId, imageElementId) {
    var path = $("#" + fileElementId).val();

    if (path == "") {
        alert("请选择上传的图片");
        return;
    }

    $.ajaxFileUpload({
        url: http_path + "/FileUpload/uploadImage",
        secureuri: false,
        fileElementId: fileElementId,
        dataType: 'text',
        success: function (data) {
            data = $.evalJSON(data);
            if (data.code < 0) {
                alert(data.msg);

                return;
            }
            $("#" + imageElementId).attr("src", data.filename);
        },
        error: function (data, status, e) {
            alert("上传图片失败");
        }
    })
}

/**
 * 上传图片
 * @param fileElementId
 * @param imageElementId
 */
function uploadImageType(fileElementId, imageElementId) {
    var path = $("#" + fileElementId).val();

    if (path == "") {
        alert("请选择上传的图片");
        return;
    }

    $.ajaxFileUpload({
        url: http_path + "/FileUpload/uploadImageReturnType",
        secureuri: false,
        fileElementId: fileElementId,
        dataType: 'text',
        success: function (data) {
            data = $.evalJSON(data);
            if (data.code < 0) {
                alert(data.msg);

                return;
            }

            $("#" + imageElementId).attr("src", data[0].filePath);
            $("#imageSize").val(data[0].size);
            $("#imageType").val(data[0].fileType);
            $("#imageResolution").val(data[0].resolution);
            $("#imageType2").html(data[0].fileType);
            $("#imageResolution2").html(data[0].resolution);
        },
        error: function (data, status, e) {
            alert("上传图片失败");
        }
    })
}

/**
 * 对Date的扩展,将 Date 转化为指定格式的String
 * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) 可以用 1-2 个占位符
 * 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
 * eg:
 * (new Date()).format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
 * (new Date()).format("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04
 * (new Date()).format("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04
 * (new Date()).format("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04
 * (new Date()).format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
 */
Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //
        "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时
        "H+": this.getHours(), //小时
        "m+": this.getMinutes(), //
        "s+": this.getSeconds(), //
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };

    var week = {
        "0": "日",
        "1": "一",
        "2": "二",
        "3": "三",
        "4": "四",
        "5": "五",
        "6": "六"
    };

    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }

    if (/(E+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "星期" : "周") : "") + week[this.getDay() + ""]);
    }

    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }

    return fmt;
}

function inputNum(obj) {
    obj.value = obj.value.replace(/\D/g, '');
}

var time = 120;//设置手机验证码时间 
var time2 = 120;
var blug;
var blug2;

//手机验证码调用时间定时器(当点击按钮是input标签时使用)
function teleCodeTimer(id) {
    blug = id;
    timer();
}

//手机验证码重新获取时间间隔
function timer() {
    $("#" + blug).attr("disabled", true);
    $("#" + blug).attr("onclick", "void(0);");
    time = time - 1;
    $("#" + blug).val(time + "秒后获取");
    if (time == 0) {
        $("#" + blug).val("获取验证码");
        time = 120;
        $("#" + blug).attr("disabled", false);
        $("#" + blug).attr("onclick", "getMobile();");
    } else {
        setTimeout('timer()', 1000);
    }
}

//手机验证码调用时间定时器(当点击按钮是a标签时使用)
function teleCodeTimer2(id) {
    blug2 = id;
    timer2();
}

//手机验证码重新获取时间间隔
function timer2() {
    $("#" + blug2).attr("disabled", true);
    time2 = time2 - 1;
    $("#" + blug2).val(time2 + "秒后获取");

    if (time2 == 0) {
        $("#" + blug2).val("获取验证码");
        time2 = 120;
        $("#" + blug2).attr("disabled", false);
    } else {
        setTimeout('timer2()', 1000);
    }
}

//手机验证码调用时间定时器(当点击按钮是a标签时使用)
function teleCodeTimer3(id) {
    blug = id;
    timer3();
}

//手机验证码重新获取时间间隔
function timer3() {
    $("#" + blug).attr("disabled", true);
    time = time - 1;
    $("#" + blug).val(time + "秒后获取");

    if (time == 0) {
        $("#" + blug).val("获取验证码");
        time = 120;
        $("#" + blug).attr("disabled", false);
    } else {
        setTimeout('timer3()', 1000);
    }
}

/**
 * 后台高亮显示
 * @param lab 大项+ - 符号
 * @param hi 隐藏项
 * @param mg 子项
 * @return
 */
function showHighLight(lab, hi, mg) {
    $("#lab_" + lab).addClass('xn_c_li_bg_jian');
    $("#hi_" + hi).show();
    $("#mg_" + mg).attr('class', 'xn_c_li_head_ishow');
    var nav_mh = $(".xn_c_content_leftul").height(),
        on_mh = $(".xn_c_con_leftbutton").height(),
        xc_ht = (nav_mh - on_mh) / 2;
    $(".xn_c_con_leftbutton").css({"margin-top": xc_ht});
}

function highLight(index) {
    $("#lab_" + index).addClass('xn_c_li_head_oneishow');
    ;
}

/* 前台选中样式 */
function showHighLightFront(index) {
    $("#child" + index).css({'background-color': '#d0ebdd', 'color': '#195a9b'});
}

/* 前台选项卡样式 */
function showHighLightFront2(maxIndex, nowIndex) {
    var li = $("#li_" + nowIndex)
    //var lab = $("#lab_" + nowIndex);
    var more = $("#more_" + nowIndex);
    var tg = $("#tg_" + nowIndex);

    li.attr('class', 'xf_con_wyjk_leftliisshow');
    more.attr('class', 'xf_mem_r_more xf_mem_r_jian');

    if (null != tg) {
        if (tg.is(":visible")) {
            tg.hide();
        } else {
            tg.show();
        }
    }
}

/* 替换被拦截的html代码,请遵循JAVA定义规则 */
function replaceAllHTML(content) {
    if (content == null || content == '')
        return '';

    content = content.replaceAll("#", "html_j");
    content = content.replaceAll("<img", "html_i");
    content = content.replaceAll("<a", "html_a");
    content = content.replaceAll("<frame", "html_f");

    return content;
}

function checkAll() {
    var allCheckBoxs = document.getElementsByName("check_box");
    var flag;

    for (var i = 0; i < allCheckBoxs.length; i++) {
        if (allCheckBoxs[i].type == "checkbox") {
            flag = allCheckBoxs[i].checked;
            allCheckBoxs[i].checked = !flag;
        }
    }
}

jQuery.fn.maxLength = function (max) {
    this.each(function () {
        var type = this.tagName.toLowerCase();
        var inputType = this.type ? this.type.toLowerCase() : null;
        if (type == "input" && inputType == "text"
            || inputType == "password") {
            // Apply the standard maxLength
            this.maxLength = max;
        } else if (type == "textarea") {
            this.onkeypress = function (e) {
                var ob = e || event;
                var keyCode = ob.keyCode;
                var hasSelection = document.selection ? document.selection
                    .createRange().text.length > 0
                    : this.selectionStart != this.selectionEnd;
                return !(this.value.length >= max
                    && (keyCode > 50 || keyCode == 32
                        || keyCode == 0 || keyCode == 13)
                    && !ob.ctrlKey && !ob.altKey && !hasSelection);
            };
            this.onkeyup = function () {
                if (this.value.length > max) {
                    this.value = this.value.substring(0, max);
                }
            };
        }
    });
};

/**
 * 金额用逗号隔开
 * @param s
 * @param n
 * @return
 */
function fmoney(s, n) {
    n = n > 0 && n <= 20 ? n : 2;
    s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
    var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];
    t = "";

    for (i = 0; i < l.length; i++) {
        t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
    }

    return t.split("").reverse().join("") + "." + r;
}

/**
 * 金额格式转化
 * @param money
 * @return
 */
function amountFormat(money) {
    var amount, result, money2;

    /*
    if(10000 < money &  money <= 100000000){
        amount = (money / 10000).toFixed(2);
        amount = fmoney(amount, 2);
        result = amount + "万";
        return result;
    }

    if(money > 100000000){
        amount = (money / 100000000).toFixed(4);
        amount = fmoney(amount, 4);
        reslut = amount + "亿";
        return result;
    }*/

    money2 = fmoney(money, 2);

    result = money2 + "";

    if (result.indexOf(".") == -1) {
        result += ".00";
    }

    return result;
}

function asterisk(str) {
    if (str == "" || str == null) {
        return "";
    }

    return str.substring(0, 1) + "**";

}

/*2015-06-23-yyy-js*/
$(function () {
    $(".xf_login_inputsrul_r>input").map(function () {
        if (!$(this).val() == "") {
            $(this).siblings("span").hide();
        }
        var text = $(this).siblings("span").text();
        $(this).bind({
            focus: function () {
                if (this.value == "") {
                    $(this).siblings("span").hide();
                    $(this).attr("placeholder", text);
                }
            },
            blur: function () {
                if (this.value == "") {
                    $(this).siblings("span").show();
                    $(this).removeAttr("placeholder");
                }
            }
        })
    })
    $(".pas1_test").map(function () {
        if (!$(this).val() == "") {
            $(this).siblings("i").hide();
        }
        var text = $(this).siblings("i").text();
        $(this).bind({
            focus: function () {
                if (this.value == "") {
                    $(this).siblings("i").hide();
                    $(this).attr("placeholder", text);
                }
            },
            blur: function () {
                if (this.value == "") {
                    $(this).siblings("i").show();
                    $(this).removeAttr("placeholder");
                }
            }
        })
    })
})

function calBidPro(loanScheduel, bidId) {
    var bidPro = loanScheduel * 1;
    var bgPos = null;

    //计算进度条位置
    var bgIndex = 0;
    if (98 < bidPro && bidPro < 100) {
        bgIndex = 49;
    } else {
        bgIndex = Math.ceil(bidPro / 2);
    }
    //var bgPos = "-" + bgIndex * 50 + "px 0";    //50px size
    //console.log(bgPos);
    var nowPos = 0;
    var obj = isNaN(parseInt(bidId)) ? bidId : $(".bid_item_status" + bidId);
    for (var i = 0; i <= bgIndex; i++) {
        setTimeout(function () {
            obj.css("background-position", "-" + nowPos * 50 + "px 0");
            nowPos++;
        }, i * 50);
    }
    //$(".bid_item_status" + bidId).css("background-position", bgPos);
}

//平台首页推荐标,转让标的切换,改变右边的全部标的链接及标题【潘集烜】
function allNormalBid() {
    $("#all_items").attr("href", "/front/invest/investHome");
    $("#all_items").html("<span>全部项目&gt;</span>");
}

function allDebtBid() {
    $("#all_items").attr("href", "/front/debt/debtHome");
    $("#all_items").html("<span>全部转让标&gt;</span>");
}

//cookie基本操作
var hzedCookieAct = {
        getCookie: function (name) {
            var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
            if (arr != null) {
                return unescape(arr[2]);
            } else {
                return null;
            }
        },
        setCookie: function (name, value, time) {
            var Days = time || 1;
            var exp = new Date();
            exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
            document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString();
        },
        addCookie: function (name, value, expiresMins) {
            var cookieString = name + "=" + escape(value);
            //判断是否设置过期时间
            if (expiresMins > 0) {
                var date = new Date();
                date.setTime(date.getTime() + expiresMins * 60 * 1000);
                cookieString = cookieString + "; expires=" + date.toGMTString();
            }
            document.cookie = cookieString;
        },
        getCookie: function (name) {
            var strCookie = document.cookie;
            var arrCookie = strCookie.split("; ");

            for (var i = 0; i < arrCookie.length; i++) {
                var arr = arrCookie[i].split("=");
                if (arr[0] == name) {
                    return unescape(arr[1]);
                }
            }
            return "";
        },
        deleteCookie: function (name) {
            var date = new Date();
            date.setTime(date.getTime() - 10000);
            document.cookie = name + "=v; expires=" + date.toGMTString();
        },
        setLocalStorage: function (key, value) {
            return localStorage.setItem(key, value)
        },
        getLocalStorage: function (key) {
            return localStorage.getItem(key)
        },
        removeLocalStorage: function (key) {
            return localStorage.removeItem(key);
        },
        getUrlParam: function (j, k) {
            var l = new RegExp('(?:[?&]|&amp;)' + j + '=([^&]+)', 'i'),
                m = (k || window).location.search.match(l);
            return m && m.length > 1 ? m[1] : null;
        },
        getAppCode: function () {
            var appCode = ''
            // appCode:(app调用的时候需要传该参数过来)合众:1 好易借:2 爱分期:3 现金白卡:4 融360:5
            var appCodeUrl = hzedCookieAct.getUrlParam('appCode')
            var appCodeCookie = hzedCookieAct.getCookie('appCode')
            // var appCodeLocalStorage=hzedCookieAct.getLocalStorage('appCode')
            var appCodeSessionStorage=window.sessionStorage.getItem('appCode')

            if (appCodeUrl != '' && appCodeUrl != null && appCodeUrl != undefined) {
                appCode = appCodeUrl
            } else if (appCodeCookie != '' && appCodeCookie != null && appCodeCookie != undefined) {
                appCode = appCodeCookie
            } else if (appCodeSessionStorage != '' && appCodeSessionStorage != null && appCodeSessionStorage != undefined) {
                appCode = appCodeSessionStorage
            }
            return appCode
        }
    }
;
(function () {
    var from = hzedCookieAct.getUrlParam('hfrom') || hzedCookieAct.getUrlParam('xfrom');
    if (!!from) {
        var time = from == 'xfrom' ? 30 : 0.1;//希财网的cookie时间为30
        hzedCookieAct.setCookie("hzedAct_fromkey", from, time);
    }
})()

/**
 * 自动跳转到手机端页面
 */
try {
    var url = window.location.href;
    if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)) && url.indexOf('www.hzed.com') >= 0) {
        // window.location="http://m.hzed.com/";
    }
} catch (err) {
}


//重置图片位置
function loadImgPos(obj, maxw, maxh, type, auto, callback) {

    //借款合同/抵押/质押合同 不重置
    var p = $(obj).next();
    if (p.text() == '借款合同' || p.text() == '抵押/质押合同' || p.text() == '车辆钥匙') {
        return false;
    }
    if (p.text() == '放款银行凭证') {
        $(obj).parent().parent().remove();
        return false;
    }
    if (p.text() == '续借协议' && location.href.indexOf('bidId=316') != -1) {
        $(obj).parent().parent().remove();
    }
    if (p.text() == '续借协议' && location.href.indexOf('bidId=812') != -1) {
        $(obj).parent().parent().remove();
    }
    var type = type || 'crop',
        auto = auto || null,
        img = new Image(),
        w, h, mt, ml;
    img.src = obj.src;
    var processPos = function (img) {
        var ow = !!img.naturalWidth ? img.naturalWidth : img.width,
            oh = !!img.naturalHeight ? img.naturalHeight : img.height;
        if (type === 'fit') {
            if (ow > oh) {
                w = ow > maxw ? maxw : ow;
                h = (oh * w) / ow;
                //再次比较
                if (h > maxh) {
                    w = (w * maxh) / h;
                    h = maxh;
                }
            } else {
                h = oh > maxh ? maxh : oh;
                w = (ow * h) / oh;
                //再次比较
                if (w > maxw) {
                    h = (h * maxw) / w;
                    w = maxh;
                }
            }
            mt = auto === 'h' ? 0 : h < maxh ? (maxh - h) / 2 : 0;
            ml = auto === 'w' ? 0 : w < maxw ? (maxw - w) / 2 : 0;
        } else if (type === 'crop') {
            if (ow > oh) {
                h = maxh;
                w = (h * ow) / oh;
            } else {
                w = maxw;
                h = (w * oh) / ow;
            }
            mt = (maxh - h) / 2;
            ml = (maxw - w) / 2;
        }
        $(obj).css({
            'width': w + 'px',
            'height': h + 'px',
            'margin-top': mt + 'px',
            'margin-left': ml + 'px',
            'visibility': 'visible'
        });
        img = null;
        $.isFunction(callback) && callback(obj);
    }
    if (obj.complete) {
        processPos(obj);
    } else {
        // img.onload = function(){
        //todo
        // }
        var flag = false;
        // 定时执行获取宽高
        var check = function () {
            // 只要任何一方大于0
            // 表示已经服务器已经返回宽高
            if (img.width > 0 || img.height > 0) {
                processPos(img);
                clearInterval(set);
            }
        };

        var set = setInterval(check, 40);
        return;
    }

}

/**
 * 日期格式var time2 = new Date().Format("yyyy-MM-dd HH:mm:ss");
 */
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //
        "s+": this.getSeconds(), //
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

/**
 * 访问到底部,执行相应的方法
 */
function autoLoadInBtm(callback) {
    var range = 100;             //距下边界长度/单位px  
    var elemt = 500;           //插入元素高度/单位px  
    var maxnum = 20;            //设置加载最多次数  
    var num = 1;
    var totalheight = 0;                     //主体元素
    var time = new Date().getTime();
    ajaxLonging = false;
    $(window).scroll(function () {
        //防止滚动过快加载多次
        if (new Date().getTime() - time <= 1000) {
            return false;
        }

        if (typeof ajaxLonging != 'undefined' && (ajaxLonging == true || ajaxLonging == 'end')) {
            console.log('end');
            return false;
        }

        var srollPos = $(window).scrollTop();    //滚动条距顶部距离(页面超出窗口的高度)  
        totalheight = parseFloat($(window).height()) + parseFloat(srollPos);
        if (($(document).height() - range) <= totalheight && num != maxnum) {
            if ($.isFunction(callback)) {
                time = new Date().getTime();
                var back = callback();
                if (back == true) {
                    ajaxLonging = false;
                } else if (back == 'end') {
                    ajaxLonging = 'end';
                } else {
                    alert('返回错误!');
                }
            }
        }
    });
}


//=====start=================新进来的方法写在前面
/**
 * 所有元素加载完成处理
 */
$(window).load(function () {

    var resetPopwin = function () {
        $('.xf_zqzr_znx_window').each(function () {
            var w = $(this).outerWidth() / 2;
            var h = $(this).outerHeight() / 2;
            $(this).css({"margin-top": "-" + h + "px", "margin-left": "-" + w + "px"});
        })
    }

    if (location.href.match(/\/account\//) !== null && !document.addEventListener) {
        setInterval(function () {
            return resetPopwin();
        }, 500);
    } else {
        resetPopwin();
    }


    $('body').delegate('.xf_zqzr_znx_window', 'DOMNodeInserted', function () {
        var w = $(this).outerWidth() / 2;
        var h = $(this).outerHeight() / 2;
        $(this).css({"margin-top": "-" + h + "px", "margin-left": "-" + w + "px"});
    });
});
/**
 * //文档加载完成处理
 */
$(function () {

    //注册提示信息
    if (location.href.indexOf('www.hzed.com/register') != -1) {
        $('.reg-act-show').find('p').html('');
    }
    //红包提示

    if (location.href.indexOf('/front/account/') != -1 || location.href.indexOf('/front/financialPlan/financialPlan') != -1 || $('.checkCoupon').length > 0 || $('.myRedCount').length > 0) {
        $.getJSON('/front/activity/countRedPackets', function (data) {
            if (data['code'] == -1) return false;
            var arr = [parseInt(data.cashRedbag), parseInt(data.investmentRedbag), parseInt(data.aprVouchers), parseInt(data.financialGold), parseInt(data.withdrawalNumber)];
            var sum = parseInt(data.cashRedbag) + parseInt(data.investmentRedbag) + parseInt(data.aprVouchers) + parseInt(data.financialGold) + parseInt(data.withdrawalNumber);
            $('.fulianniu,.viewcoupon,.myRedCount').append('<em class="myRegCount">' + sum + '</em>');
            if (location.href.indexOf('/front/account/bidEnvelope') != -1) {
                var enObj = $('.envelope');
                for (var i = 0; i < arr.length; i++) {
                    if (arr[i] == 0) continue;
                    enObj.find('li').eq(i).children().append('<em>' + arr[i] + '</em>');
                }
            }
            if (location.href.indexOf('/wechat/investAction/queryBidDetail') > -1) {
                $('.fulianniu,.viewcoupon,.myRedCount').append('<em class="myRegCount">' + (parseInt(data.investmentRedbag) + parseInt(data.aprVouchers) + parseInt(data.financialGold) + parseInt(data.withdrawalNumber)) + '</em>');
            }
            //微信智盈存暂时隐藏掉红包和加息券的选择
            if (location.href.indexOf('/wechat/investAction/queryBidDetailZhiyin') > -1) {
                $(".ly_bttab_K.viewcoupon").remove();
            }
        });
    }

    addDownloadFloat()
});
//=====end=================新进来的方法写在前面

/**
 * 获取URL上面的参数
 */
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURI(r[2]); return null;
}

function addDownloadFloat() {
    if(location.pathname.indexOf('/wechat/home/home') != -1 ||
        location.pathname.indexOf('/wechat/investAction/queryAllBids') != -1) {
        // 添加浮层
        $('body').prepend('<div class="app-download-wrap clearfix">' +
            '<div class="logo left"></div>' +
            '<div class="adw-text left"><span>下载合众e贷APP,<br>享更好体验!</span></div>' +
            '<a href="/app/download"><div class="btn-download-app left">点击下载</div></a>' +
            '<div class="btn-close"></div>' +
            '</div>')
        // var close_download_float_config = hzedCookieAct.getLocalStorage('close_download_float_config')
        // if (close_download_float_config == null) {
        //     var obj = {}
        //     hzedCookieAct.setLocalStorage('close_download_float_config', JSON.stringify(obj))
        // } else {
        //     if (close_download_float_config != '{}') {
        //         if (Math.floor(((new Date().getTime() - JSON.parse(close_download_float_config).closeDate) / 86400000)) >= 1) {
        //             // 大于一天,重置浮层
        //             hzedCookieAct.removeLocalStorage('close_download_float_config')
        //             $('.app-download-wrap').show()
        //         }
        //         if (JSON.parse(close_download_float_config).isShow == '0') {
        //             $('.app-download-wrap').hide()
        //         } else {
        //             $('.app-download-wrap').show()
        //         }
        //     } else {
        //         hzedCookieAct.deleteCookie('close_download_float_config')
        //     }
        // }
        $('.app-download-wrap .btn-close').click(function () {
            // 关闭浮层
            // obj = {
            //     closeDate: new Date().getTime(),
            //     isShow: '0'
            // }
            // hzedCookieAct.setLocalStorage('close_download_float_config', JSON.stringify(obj))
            $('.app-download-wrap').hide()
        })
    }
}

 

var totalPages;//总页数
var pageno = 0;//当前页数
$(function(){
    $(window).scroll(function() {
       var scrollTop = $(this).scrollTop(),scrollHeight = $(document).height(),windowHeight = $(this).height();
       var positionValue = (scrollTop + windowHeight) - scrollHeight;
       if (positionValue == 0) {
           //do something
           if (pageno < totalPages - 1) {
               pageno++;
               doSomething(pageno);
           } else {
               alert('没有更多了');
           }
       }
   });
);
 
function doSomething(pageno) {
        var url = "*******";//分页列表的接口
        var data = {
                size: 5,
                start: pageno,
        };
        $.getJSON(url, data, function (rtn) {
                
        });
}
html,body{ height:auto }

getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
//var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
var r = window.location.search.substr(1).match(reg);
//var q = window.location.pathname.substr(1).match(reg_rewrite);
return r ? unescape(r[2]) : null;
},

 

 //多行文本超出处理

.box {
    width: 400px; 
    display: -webkit-box;
word-break: break-all; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
text-overflow: ellipsis;

}
-webkit-tap-highlight-color:transparent是一个没有标准化的属性,能够设置点击链接的时候出现的高亮颜色。
  1. -webkit-box-orient: vertical;
  2. -webkit-box-direction: normal;  div 中元素顺序 方向

 

div
{
width:350px;
height:100px;
border:1px solid black;

/* Firefox */
display:-moz-box;
-moz-box-pack:center;
-moz-box-align:center;

/* Safari、Opera 以及 Chrome */
display:-webkit-box;
-webkit-box-pack:center;
-webkit-box-align:center;

/* W3C */
display:box;
box-pack:center;
box-align:center;
}

 

//滚动处理代码

windowScrollHandler() {
                if (!window.TICKING) {
                    window.TICKING = true;
                    requestAnimationFrame(this.scrollMonitor);
                }
            },
            scrollMonitor(){
                window.TICKING = false;
                if ((document.documentElement.scrollTop > 453 || document.body.scrollTop > 453)) {
                    this.bottomFlag = true;
                } else {
                    this.bottomFlag = false;
                    
                }
            },

window.onscroll = this.windowScrollHandler;(mounted)

 https://github.com/nefe/You-Dont-Need-jQuery/blob/master/README.zh-CN.md

posted @ 2018-08-30 16:56  创业男生  阅读(255)  评论(0编辑  收藏  举报