如何在 php MVC 框架中使用 ajax 调用替换 jcarousel 滑块 html


How to replace jcarousel slider html using ajax call in php MVC framework

我的php Web应用程序中有两个jcarousel滑块,一个用于选择月份,另一个用于与该月份相关的日期,我想使用jquery ajax来做到这一点, 无论我选择哪个月份,所有日期都应该出现在第二个滑块中,有什么办法请帮忙。

首先设置月份和日期的基本html。

<ul id="months" class="jcarousel-skin">
    <li>Jan</li>
    <li>Feb</li>
    <li>Mar</li>
    <li>Apr</li>
    <li>May</li>
    <li>Jun</li>
    <li>Jul</li>
    <li>Aug</li>
    <li>Sep</li>
    <li>Oct</li>
    <li>Nov</li>
    <li>Dec</li>
</ul>
<ul id="dates" class="jcarousel-skin">
</ul>

现在在javascript设置月份的轮播和日期ajax

$(document).ready(function(){
    $('#months').jcarousel();
    // Assuming you are going to load months' dates onclick
    $('#months > li').click(function(){
        $.ajax({
            url : 'your-server-script.php?month=' . $(this).text(),
            success : function(data){
                /* Return the dates as html in li tags from server
                    <li>1, Friday</li><li>2, Saturday</li> .... <li>30, whatever</li>
                   and put in the dates ul.
                   You can also pass json(or any other format) and create the html here and put it in.
                */
                $('#dates').html(data);
                // Now setup the dates carousel.
                $('#dates').jcarousel();
            }
        });
    });
});

希望这有帮助。如果您还有其他问题,请与 html 一起粘贴。