javascript - jQuery:查找包含特定文本的元素

标签 javascript jquery drupal

我的页面上有一个日历,下面有一个事件列表。当用户单击下一个或上一个按钮时,我想用仅包含日历上当前显示的月份和年份的行内容填充一个 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'");

See this example on jsFiddle

关于javascript - jQuery:查找包含特定文本的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5862218/

相关文章:

javascript - 如何向 jquery 追加添加淡入淡出效果

javascript - 处理来自 REST API 的客户端错误

javascript - 使用 jquery 从 HTML 表中提取数据

jQuery .position().left 和变量

drupal - 设置哪些 block 将出现在 Drupal 安装配置文件中的页面

php - 如何自动删除 Drupal 7.x 中的旧 Feed 项目?

drupal - 在每个页面上缓存具有 session 特定数据的 Drupal 站点

javascript - 旋转的 div 显示在彼此之上

javascript - 接收 JSON 格式的图像数据并将其注入(inject) DOM

javascript - 谷歌图表 : points on line graph not showing