2012-10-23 22 views
0

我使用This Timer Plugin創建一個定時器,一旦單擊按鈕。您可以see it in action here.如果您注意到,當您單擊任何購買按鈕兩次時,它將被忽略並不會再次執行。我無法弄清楚如何解決這個問題。我需要定時器在計時器完成後隨時點擊按鈕重新啓動。定時器插件在執行一次後將無法工作

這裏是我使用的第一個按鈕的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插件,you can find it live here.

+0

我仍然需要幫助! –

回答

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 
} 
相關問題