2015-11-02 45 views
2

我有一系列使用按鈕填充的div類。我只需要在CURRENT日的特定時間過後才能禁用按鈕,以避免用戶點擊它們。使用PHP禁用div類中的href按鈕使用PHP

我能夠使用this solution得到這種工作,但它並沒有解決只爲CURRENT日做這件事,並沒有禁止只點擊按鈕。

我真的不知道從哪裏開始?

這是我的div。例如,如果是過去的1400我想禁用Zillow的-4格,如果它過去的1600我想禁用Zillow的-5:

<div id="zillow-4" style="height:50px;"><a class="button " href="updateScheduleRequest.php?slotid=4&amp;timeremain=110&amp;current_date=2015-11-02&amp;empnum=702">Assign Slot 4</a></div> 

<div id="zillow-5" style="height:50px;"><a class="button " href="updateScheduleRequest.php?slotid=5&amp;timeremain=110&amp;current_date=2015-11-02&amp;empnum=702">Assign Slot 5</a></div> 

回答

2

我想這你想要做什麼?

<script type="text/javascript" > 
    $(function(){ 
     disableChildButtonByTime(14, 0, "zillow-5");  
     disableChildButtonByTime(16, 0, "zillow-4");  

     function disableChildButtonByTime(hour, minute, parentId){ 
      var date = new Date(); 
      if(date.getHours() >= hour && date.getMinutes() >= minute){ 
       $("#" + parentId).children(".button").addClass("disabled"); 
      } 
     } 
    }); 
</script> 

例如:https://jsfiddle.net/eLegckag/1/

自動更新版本(此檢查時間每分鐘一次):

https://jsfiddle.net/eLegckag/2/

+0

這看起來不錯,但我發現在功能disableChildButtonByTime語法錯誤創建邏輯() ? @dhunt ...沒有其他消息,但...有任何想法? –

+0

你使用什麼瀏覽器?我沒有看到任何錯誤,使用Chrome。此外,進行了編輯,以便數據變量不再是全局的。 – Dhunt

+0

在Chrome中,它引發了一個500服務器錯誤,在Dreamweaver中,我在函數行中得到了一個語法錯誤@dhunt –

0

使用PHP,你可以使用:

<div id="zillow-4" style="height:50px;"><a class="button " href="<?= (date('G') >= 14) ? '#' : 'updateScheduleRequest.php?slotid=4&amp;timeremain=110&amp;current_date=2015-11-02&amp;empnum=702' ?>">Assign Slot 4</a></div>

0

問題是使用PHP和JS

你用PHP第一

$time = // what time? 

然後

@ref: http://stackoverflow.com/questions/10276133/how-to-disable-html-links