简体   繁体   English

根据月份将内容加载到div中

[英]Load content into div based on month

I am needing to load content for the specific month defined by the user. 我需要加载用户定义的特定月份的内容。 If the user picks the month of July, a list of events (the content in the this case) is shown for the month of July. 如果用户选择7月,则会显示7月的事件列表(本例中为内容)。 If the user picks June, all of the June events are shown. 如果用户选择6月,则将显示所有6月事件。 Right now, I have a script set up to where the user clicks a "next" link to switch months. 现在,我已经设置了一个脚本,用户可以在该脚本中单击“下一个”链接来切换月份。 Only month is shown at a time. 一次仅显示一个月。 When the user clicks the "next" link, I would like for all of the next months content to load. 当用户单击“下一个”链接时,我希望在接下来的几个月中加载所有内容。 For example, if the user is on the month of June and they click next than July will will show up as well as all of the July events. 例如,如果用户在六月,并且单击下一步,则将显示七月以及所有七月的事件。 To load the new events I am using: 要加载我正在使用的新事件:

window.location = "/<?php echo $site_slug; ?>/ministries/events/<?php echo $_GET['year']; ?>/<?php echo $_GET['month']; ?>;

This is called when the user clicks the "next" button. 当用户单击“下一步”按钮时,将调用此方法。 The $_GET['year'] and $_GET['month'} variables are being populated by an API. API填充了$ _GET ['year']和$ _GET ['month'}变量。 When I click the next button, I am not getting the "year" and "month" values but just a hashtag. 当我单击下一步按钮时,我没有得到“年”和“月”值,而只是得到了一个标签。 My question is, is the javascript syntax correct? 我的问题是,javascript语法正确吗?

EDIT: Added more code: 编辑:添加了更多代码:

Jquery: jQuery:

    <script type="text/javascript">
        $('document').ready(function(){
            $(".event_months li:nth-child(3)").addClass("doShow");

            $("a.next").click(function() {
                $('.first').toggleClass("first");
                var $toHighlight = $('.doShow').next().length > 0 ? $('.doShow').next() : $('.event_months li').first();
                $('.doShow').removeClass('doShow');
                $toHighlight.addClass('doShow');
                window.location = "/<?php echo $site_slug; ?>/ministries/events/<?php echo $_GET['year']; ?>/<?php echo $_GET['month']; ?>;

            });

          });
     </script>

Not sure if the API call will help but here it is: 不确定API调用是否会有所帮助,但是在这里是:

<?php getContent(
    "event",
    "display:list", 
    "order:recent",
    "find_group:".$site_slug,
    "groupby:month",
    "year:".$_GET['year'], 
    "month:".$_GET['month'],
    "group_show:<li class='noShow'>__slug__</li>"
    ); 
?> 

I setup your code like you did (I had to guess at the "next" link), and couldn't get it to work. 我像您一样设置了您的代码(我不得不猜测“下一个”链接),但无法正常工作。 The problem, from what I can tell, is that you're using $_GET to get the year and month variables from the URL. 据我所知,问题在于您正在使用$_GET从URL获取年份和月份变量。 Use $_REQUEST , instead: 使用$_REQUEST ,而不是:

<a class="next" href="/?year=2012&month=06" onclick="return false;">Next</a>

You'll also need the "return false" to stop the link from following, IF you want to use your window.location line. 如果您要使用window.location行,则还需要“ return false”以阻止链接继续。

Don't forget (like you've mentioned) to make sure your window.location has a closing parenthesis. 不要忘记(就像您提到的那样)确保window.location带有圆括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM