使用JQuery Selector时遇到困难

时间:2011-10-19 23:19:53

标签: jquery selector

好的,我知道我在这里遗漏了一些东西。我正在尝试ajaxify日历。日历加载html链接到其他页面。我的部分工作正在进行,但我很难找到其他月份的导航链接。

我可以加载日历,显示日历,甚至可以在单击事件链接时打开和关闭模式对话框。我无法工作的是更改表头中prev和next链接的url。

谢谢你的帮助。

这是jquery:

$(document).ready(function() {

/*-------------------------------------*/
/*       Event Calendar Methods        */
/*-------------------------------------*/
$.ajax({ url: '<?php echo site_url("servicebay/ajax/getCalendar");?>', success:    function( data ) {

    // Setup the calendar
    $("#calendar").html(data);
    // Setup event lists
    $('.event-detail-link').click(function(eventdata){
        var href = $(this).attr('href');
        //alert('Event Click'+ $(this).text()+' '+href);
        $.ajax({url: href, success: function(data) {
            $('#basic-modal-content').html(data);
            $('#basic-modal-content').modal({escClose:true, backgroundColor:"#FFCC00", borderColor:"#FFCC00"});
            return false;
        }}
        ); //End click()
        // Event-detail-link failure
        return false;
    });

    /* Calendar Next Link */
    /* <a id="calendar-next-nav" href="http://localhost/mysite/calendar/index/2011/11">&gt;&gt;</a>*/       
    $('#calendar-next-nav').click(function(eventdata){
        var href = $(this).attr('href');
        var x = href.substring(x.lastIndexOf("/")+1, x.lastIndexOf("/"));
        alert('Clicked'+ x);
        $(this).attr('href') ='/servicebay/ajax/getCalendar/'+x;
        return false;
    });

  }
});
});

html:

<div id="calendar"><table id="" class="calendar">

<tbody><tr>
<th><a id="calendar-prev-nav" href="http://localhost/mysite/calendar/index/2011/09">&lt;&lt;</a></th>
<th colspan="5">October&nbsp;2011</th>
<th><a id="calendar-next-nav" href="http://localhost/mysite/calendar/index/2011/11">&gt;&gt;</a></th>
</tr>

<tr>
<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
</tr>

<tr class="calendar-days">
<td class="calendar-day">&nbsp;</td><td class="calendar-day">&nbsp;</td><td class="calendar-day">&nbsp;</td><td class="calendar-day">&nbsp;</td><td class="calendar-day">&nbsp;</td><td class="calendar-day">&nbsp;</td><td class="calendar-day"><div class="calendar-day-num">1</div></td>
</tr>

<tr class="calendar-days">
<td class="calendar-day"><div class="calendar-day-num">2</div></td><td class="calendar-day"><div class="calendar-day-num">3</div></td><td class="calendar-day"><div class="calendar-day-num">4</div></td><td class="calendar-day"><div class="calendar-day-num">5</div></td><td class="calendar-day"><div class="calendar-day-num">6</div></td><td class="calendar-day"><div class="calendar-day-num">7</div></td><td class="calendar-day"><div class="calendar-day-num">8</div></td>
</tr>

<tr class="calendar-days">
<td class="calendar-day"><div class="calendar-day-num">9</div></td><td class="calendar-day"><div class="calendar-day-num">10</div></td><td class="calendar-day"><div class="calendar-day-num">11</div></td><td class="calendar-day"><div class="calendar-day-num">12</div></td><td class="calendar-day"><div class="calendar-day-num">13</div></td><td class="calendar-day"><div class="calendar-day-num">14</div></td><td class="calendar-day"><div class="calendar-day-num">15</div></td>
</tr>

<tr class="calendar-days">
<td class="calendar-day"><div class="calendar-day-num">16</div></td><td class="calendar-day"><div class="calendar-day-num">17</div></td><td class="calendar-day"><div class="calendar-day-num">18</div></td><td class="calendar-day"><div class="calendar-day-num highlight">19</div></td><td class="calendar-day">
                <div class="calendar-day-num">20</div>
                <div class="calendar-content"><ul class="calendar-event-list"><li><a class="event-detail-link" href="http://localhost/mysite/servicebay/ajax/eventDetail/7">Oil Change</a></li></ul></div>
           </td><td class="calendar-day"><div class="calendar-day-num">21</div></td><td class="calendar-day"><div class="calendar-day-num">22</div></td>
</tr>

<tr class="calendar-days">
<td class="calendar-day"><div class="calendar-day-num">23</div></td><td class="calendar-day"><div class="calendar-day-num">24</div></td><td class="calendar-day"><div class="calendar-day-num">25</div></td><td class="calendar-day"><div class="calendar-day-num">26</div></td><td class="calendar-day"><div class="calendar-day-num">27</div></td><td class="calendar-day"><div class="calendar-day-num">28</div></td><td class="calendar-day"><div class="calendar-day-num">29</div></td>
</tr>

<tr class="calendar-days">
<td class="calendar-day"><div class="calendar-day-num">30</div></td><td class="calendar-day"><div class="calendar-day-num">31</div></td><td class="calendar-day">&nbsp;</td><td class="calendar-day">&nbsp;</td><td class="calendar-day">&nbsp;</td><td class="calendar-day">&nbsp;</td><td class="calendar-day">&nbsp;</td>
</tr>

</tbody></table></div>

1 个答案:

答案 0 :(得分:2)

使用.attr方法时,将要设置属性的值传递给方法的第二个参数。

$('selector').attr('attribute', 'value_to_set');

查看jquery documentation以获取更多解释。