我的页面上有一个日历,下面有一个事件列表。当用户单击下一个或上一个按钮时,我想用仅包含日历上当前显示的月份和年份的行内容填充一个 div。这是行的结构(使用 Drupal 7 Views 创建)。
<div id="all-events">
<div class="views-rows">
<div class="field-date">
<div class="field-content">
<span>June 2011</span>
</div>
</div>
</div>
<div class="views-rows">
<div class="field-event-title">
<div class="field-content">
<span>Some Event</span>
</div>
</div>
</div>
</div>
我已经使用 jQuery 走到这一步了,但是我收到了一大堆错误:
$('#calendar span.fc-button-next').live('click', function(){
var month = $('#calendar .fc-header-title h2').html();
$('.event-list').fadeOut(350, function(){
$(this).html('');
$('#all-events').each('.views-rows',function(){
// Code goes here...
});
});
});
我还应该提到,我正在使用 FullCalendar 创建日历,因此它是使用此插件创建的。现在我可以获得用户正在查看的当前月份,但我想遍历列表并找到包含这个月的所有行并将它们显示在 .event-list div 中。
最佳答案
我无法完全理解您想要什么,但要按文本过滤元素,请使用 filter
<div>text 1</div>
<div> not this text </div>
JS
$("div").filter(function(){
return $(this).text().indexOf("text 1") >= 0; // if contains desired text
}).html("this one matches 'text 1'");
关于javascript - jQuery:查找包含特定文本的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5862218/