2013-04-26 98 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