0

单击按钮后,我正在使用此计时器插件创建计时器。你可以在这里看到它的实际效果。如果您注意到,当您单击任何购买按钮两次时,它会被忽略并且不会再次执行。我无法弄清楚如何纠正这个问题。计时器完成后,只要单击按钮,我就需要重新启动计时器。

这是我在第一个按钮上使用的 HTML:

<h3 class="protection"><span id="sentryTime">00:00:00</span><a href="javascript:sentry()">Purchase Sentry</a></h3>

这是我在该按钮上使用的javascript,它调用插件来创建计时器:

function sentry() {
    var dateCreated1 = new Date();
    setCharacterTime(/*hr*/0,/*min*/0,/*sec*/5,/*title*/'sentryTime',dateCreated1)} 


function setCharacterTime(hours, minutes, seconds, title, creationDate) {

    var thisDay = creationDate;
    var year = thisDay.getFullYear();
    var month = thisDay.getMonth();
    var day = thisDay.getDate();
    var aHour = thisDay.getHours();
    var aMinutes = thisDay.getMinutes();
    var aSeconds = thisDay.getSeconds();
    var aMilli = thisDay.getMilliseconds();
    thisDay = new Date(year, month, day, aHour + hours, aMinutes + minutes, aSeconds + seconds, aMilli);
    $('#' + title).countdown({until: thisDay, format: 'HMS', layout: ' {hnn}{sep}{mnn}{sep}{snn}', expiryText: 'complete '});
    ;} //end setCharacterTime() function 

如果您需要查看 jQuery 插件,可以在这里找到它。

4

1 回答 1

0

这是我从插件作者那里收到的解决方案:

function sentry() {
    setCharacterTime('+5s', 'sentryTime');
}
function security() {
    setCharacterTime('+5m', 'securityTime');
}
function police() {
    setCharacterTime('+8m', 'policeTime');
}
function soldier() {
    setCharacterTime('+1h', 'soldierTime');
}
function warrior() {
    setCharacterTime('+1h +45m', 'warriorTime');
}
function setCharacterTime(offset, title) {
    var alertStatement = 'this is supposed to pop up once the timer is complete.';
    $('#' + title).countdown({format: 'HMS', layout: ' {hnn}{sep}{mnn}{sep}{snn}', // Initialise
        onExpiry: function() {
            alert(alertStatement);
        }
    }).countdown('option', {until: offset});// Update
}
于 2012-10-25T01:56:37.007 回答