2011-07-07 175 views
0

我有一個腳本。 jQuery datepicker與數據庫上的網址。在jQuery datepicker中更改鏈接背景

<script> 
    $(function() { 
      $('#datepicker').datepicker({ 
       beforeShowDay: daysToMark, 
       onSelect: function(date,evt){ 
        if (evt.currentMonth < 10){ 
         evt.currentMonth = "0"+evt.currentMonth; 
         } 
        if (evt.currentDay < 10){ 
         evt.currentDay = "0"+evt.currentDay; 
         } 
         daysToMark(evt.currentYear+"-"+evt.currentMonth+"-"+evt.currentDay); 
         date.dpDiv.find('.ui-datepicker-current-day a') 
         .css('background-color', '#000000'); 
         } 
       }); 
     }); 

     <? 
     $dateArray = array(); 
     $sql = mysql_query("SELECT * 
          FROM module_news 
          "); 
       while ($row = mysql_fetch_array($sql)) { 
        array_push($dateArray,$row["tarigi"]); 
        } 
     ?> 
     var js_array = new Array(); 
     js_array = <?=json_encode($dateArray);?>; 
     var dates = js_array; 
     function daysToMark(evt) { 
      if($.inArray(evt, js_array) != -1) 
      { 

       window.open("index.php?action=news_archive&date="+evt+"&lang=<?=$lang?>", "_self"); 
      } 
     return [true, "", ""]; 
     } 
     </script> 

我在陣列數據庫日期鏈接,我想強調的聯繫,所以當我在2011-07-08我的日曆上它會被鏈接,但不突出,寫新聞我怎麼能更改鏈接日期的背景顏色?

感謝

回答

1

daysToMark方法中,您根據beforeShowDay事件的要求返回return [true, "", ""];

該數組中的第二個位置包含將應用於數據的類。所以,如果你添加一個類有return [true, "linked", ""];和你的CSS代碼中設置的

.linked .ui-state-default{ 
    background-color:red; 
    background-image:none; /*this in case the them you use uses background images*/ 
} 

規則應該做你想要什麼..

演示在http://jsfiddle.net/gaby/S79fa/

0

替換爲下面的代碼

var atag = date.dpDiv.find('.ui-datepicker-current-day a'); 
atag.queue(function() { 
    atag.css("background-color", "black"); 
}); 

此行

date.dpDiv.find('.ui-datepicker-current-day a') 
         .css('background-color', '#000000'); 

這可能是有益的

感謝。