2013-04-26 99 views
3

我想申请这个酥料饼只在正则表达式匹配

$('.body').popover({ 
    html: true, 
    trigger: 'hover', 
    placement: 'top', 
    container: 'body', 
    content: function() { 
    return '<img src="'+$(this).attr('href') + '" />'; 
    } 
}); 

应用引导酥料饼只有0​​

我不知道如何做到这一点..因为我不能做之前的状态,如果我已经在弹出窗口内,它已经太晚了

回答

0

我结束了使用过滤器来过滤它像这样

$('.body').filter(function() { 
    return /(jpg|gif|png)$/.test($(this).attr('href')) 
}).popover({ html: true, 
      trigger: 'hover', 
      placement: 'top', 
      container: 'body', 
      content: function() { 
       return '<img src="'+$(this).attr('href') + '" />'; 
      } 
      }); 
2

而不是在弹出窗口中这样做,你可以遍历所有类body的项目,并添加一个新的类(例如imgbody),如果它匹配某些条件秒。然后,您只为该课程创建弹出窗口。

所以:

$('.body').each(function(index, elem) { 
    if (/(jpg|gif|png)$/.test($(elem).attr('href'))) 
    $(elem).addClass("imgbody"); 
}); 
$(".imgbody").popover({ ... 
+0

那是可能的,我结束了使用过滤器() – 2013-04-26 16:49:22

+0

您的解决方案,但是,在更灵活长跑 – 2013-04-26 16:50:59