开发者

change link background in jQuery datepicker

i have a script. jQuery datepicker with url's on database.

<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');
                        开发者_如何学Go}
                });
        });

        <? 
        $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>

I have database date links in array, and i want to highlight links, so when i write news at 2011-07-08 on my calendar it 'll be linked but not highlighted, how can i change background color of linked dates?

thanks


In the daysToMark method you return return [true, "", ""]; as required by the beforeShowDay event.

The second position in that array hold a class that will be applied to the data. So if you add a class there return [true, "linked", ""]; and in you css code set a rule of

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

it should do what you want..

demo at http://jsfiddle.net/gaby/S79fa/


replace this line

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

with below code

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

this may be helpful

Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜