本帖最后由 xiaop14 于 2015-01-31 20:55:38 编辑

解决方案 »

  1.   

    function changeTwoDecimal(x) {
                var f_x = parseFloat(x);
                if (isNaN(f_x)) {
                    return false;
                }
                f_x = Math.round(f_x * 100) / 100;
                var s_x = f_x.toString();
                var pos_decimal = s_x.indexOf('.');
                if (pos_decimal < 0) {
                    pos_decimal = s_x.length;
                    s_x += '.';
                }
                while (s_x.length <= pos_decimal + 2) {
                    s_x += '0';
                }
                return s_x;
            }        var __sto = setTimeout;
            window.setTimeout = function (callback, timeout, param) {
                var args = Array.prototype.slice.call(arguments, 2);
                var _cb = function () {
                    callback.apply(null, args);
                }
                __sto(_cb, timeout);
            }        var nowTime = new Date("2015-1-31 19:58:27".replace(/-/g, "/"));        $(function () {            $(".m_list").each(function () {
                    var _beginTime = new Date($(this).find(".cur_begintime").html().replace(/-/g, "/"));
                    var _endTime = new Date($(this).find(".cur_endtime").html().replace(/-/g, "/"));
                    var _inventory = $(this).find(".cur_mscount").html();                CountDown(_beginTime.getTime(), _endTime.getTime(), nowTime.getTime(), _inventory, this);            });        });        //抢购倒计时
            function CountDown(_beginTime, _endTime, _period, _inventory, ele) {
                //倒计时
                var dateDiff;
                if (_beginTime > _period) { //未开始
                    if ($(ele).find(".btn_order").html() != "未开始") {
                        $(ele).find(".btn_order").html("未开始");
                        $(ele).find(".btn_order").removeClass("ks").addClass("wks");
                        $(ele).find(".cur_tips").html("距开始还有");                }                dateDiff = _beginTime - _period;
                    var _p = _period + 1000;
                    Counter(dateDiff, ele);
                    var waitCounter = window.setTimeout(CountDown, 1000, _beginTime, _endTime, _p, _inventory, ele);
                }
                else {
                    if (_endTime < _period || _inventory <= 0) {
                        //时间过期或无库存 --已结束                    if ($(ele).find(".btn_order").html() != "已结束") {
                            $(ele).find(".btn_order").html("已结束");
                            $(ele).find(".btn_order").removeClass("ks").addClass("wks");
                            $(ele).find(".btn_order").unbind("click");
                            $(ele).find(".cur_tips").html("已结束");                        $(ele).find(".cur_countDown").hide();//隐藏结束倒计时
                        }                }
                    else {
                        //未过期并且有库存 --正在进行
                        if ($(ele).find(".btn_order").html() != "立即开抢") {                        $(ele).find(".btn_order").html("立即开抢");
                            $(ele).find(".btn_order").removeClass("wks").addClass("ks");
                            $(ele).find(".cur_tips").html("结束倒计时");                        $(ele).find(".btn_order").click(function () {
                                order($(this).attr("miaoShaProId"));
                            });                        $(ele).find(".cur_countDown").hide();//隐藏结束倒计时                    }                    dateDiff = _endTime - _period;
                        Counter(dateDiff, ele); //计时                                          //价格控制
                        var _lastDiff = _period - _beginTime;  //已持续时间                    //走你
                        _period += 1000;
                        var beginCounter = window.setTimeout(CountDown, 1000, _beginTime, _endTime, _period, _inventory, ele);
                    }
                }
            }        //计时器
            function Counter(dateDiff, ele) {
                if (dateDiff > 0) {
                    var hourDiff = Math.floor(dateDiff / (3600 * 1000));                var leftSecond2 = dateDiff % (3600 * 1000)
                    var minuteDiff = Math.floor(leftSecond2 / (60 * 1000))
                    var leftSecond3 = leftSecond2 % (60 * 1000)
                    var secondDiff = Math.round(leftSecond3 / 1000)
                    if (hourDiff < 10) {
                        $(ele).find(".ct_hour").html("0" + hourDiff);
                    }
                    else {
                        $(ele).find(".ct_hour").html(hourDiff);
                    }
                    if (minuteDiff < 10) {
                        $(ele).find(".ct_minute").html("0" + minuteDiff);
                    }
                    else {
                        $(ele).find(".ct_minute").html(minuteDiff);
                    }
                    if (secondDiff < 10) {
                        $(ele).find(".ct_second").html("0" + secondDiff);
                    }
                    else {
                        $(ele).find(".ct_second").html(secondDiff);
                    }
                }
                else //已结束
                {
                    $(ele).find(".ct_hour").html("00");
                    $(ele).find(".ct_minute").html("00");
                    $(ele).find(".ct_second").html("00");
                }
            }        function loadVC(miaoShaProId) {
                $("#VerifyCodeImage").attr("src", "/VerifyCode/RandomPB?T=10109&msid=" + miaoShaProId + "&r=" + Math.random());
            }        function order(miaoShaProId) {
                var verifyCodeImgSrc = "/VerifyCode/RandomPB?T=10109&msid=" + miaoShaProId + "&r=" + Math.random();
                $.Dialog({
                    title: "请输入验证码",
                    content: "<div>请输入验证码,再提交!</div><div class=b></div><input name='username' id='txtVerifyCode' type='text' maxlength='4' style='width:96%'><img id='VerifyCodeImage' onclick='loadVC(" + miaoShaProId + ")' src='" + verifyCodeImgSrc + "'/>点击图片更新验证码",
                    button: {
                        " 提 交 ": function (e) {
                            var verifyCode = $.trim($("#txtVerifyCode").val());
                            if (verifyCode == "") {
                                $.tip("请输入验证码!", 3);
                                return false;
                            }                        $.post("/Game/Order", { miaoShaProId: miaoShaProId, T: 10109, verifyCode: verifyCode }, function (j) {
                                if (j.isResult) {
                                    location.href = j.msg;
                                }
                                else {
                                    $.tip(j.msg, 10);
                                }
                            }, "json");
                        },
                        " 关 闭 ": function (e) { e.close() }
                    }
                });        }这是该页面的一些F12源码。。
      

  2.   

    $("input").keyup(function(event){
      if(event.keyCode ==13){
       submit()
      }
    });