0

私はオークションサイトを構築しており、各商品にはカウントダウンタイマーが付いています。

ここから作業スクリプトを取得しました(stackoverflow)->入札Webサイトのカウントダウンタイマーの作成方法

これは私のコードです

<script>
    var before = ""
    var current = "Ended"
    var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

    jQuery.fn.countdown = function(yr, m, d) {
        $that = $(this);
        theyear = yr;
        themonth = m;
        theday = d;
        var today = new Date();
        var todayy = today.getYear();
        if (todayy < 1000)
            todayy += 1900;
        var todaym = today.getMonth();
        var todayd = today.getDate();
        var todayh = today.getHours();
        var todaymin = today.getMinutes();
        var todaysec = today.getSeconds();

        var todaystring = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec

        futurestring = montharray[m - 1] + " " + d + ", " + yr;
        dd = Date.parse(futurestring) - Date.parse(todaystring);
        dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
        dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
        dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
        dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);

        if (dday < 0 && dhour < 0 && dmin < 0 && dsec < 1) {
            $that.val(current);
            return;
        }
        else
            $that.val(dday + "Days, " + dhour + ":" + dmin + ":" + dsec + before);
        setTimeout(function() {
            $that.countdown(theyear, themonth, theday);
        }, 1000);
    };
</script>

<input type="text" id="6" style="width: 900px">
<script>        
    $("#6").countdown(2011, 7, 27);
</script>

私の質問は、これに時間を追加するにはどうすればよいですか? 私はこれを操作して時間とともに動作させるためのJavaScriptの経験があまりありません

4

2 に答える 2

0

解決策を得た

<script>
var before = ""
var current = "Ended"
var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

jQuery.fn.countdown = function(yr, m, d, h, min, s) {
    $that = $(this);
    theyear = yr;
    themonth = m;
    theday = d;
    thehour = h;
    theminute = min;
    thesecond = s;

    var today = new Date();
    var todayy = today.getYear();
    if (todayy < 1000)
        todayy += 1900;
    var todaym = today.getMonth();
    var todayd = today.getDate();
    var todayh = today.getHours();
    var todaymin = today.getMinutes();
    var todaysec = today.getSeconds();

    var todaystring = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec;
    futurestring = montharray[m - 1] + " " + d + ", " + yr + " " + h + ":" + min + ":" + s;
    //console.log(futurestring);
    dd = Date.parse(futurestring) - Date.parse(todaystring);
    dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
    dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
    dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
    dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);

    if (dday < 0 && dhour < 0 && dmin < 0 && dsec < 1) {
        $that.text(current);
        return;
    }
    else {
        $that.text(dday + "Days " + dhour + ":" + dmin + ":" + dsec + before);
    }

    setTimeout(function() {
        $that.countdown(theyear, themonth, theday, thehour, theminute, thesecond);
    }, 1000);
};
</script>
<input type="text" id="6" style="width: 900px">
<script>        
$("#6").countdown(2011, 7, 27, 12, 13, 12);
</script>
于 2013-07-26T19:29:30.680 に答える