我想要应用此弹出窗口
$('.body').popover({
html: true,
trigger: 'hover',
placement: 'top',
container: 'body',
content: function () {
return '<img src="'+$(this).attr('href') + '" />';
}
});仅当/(jpg|gif|png)$/.test($(this).attr('href'))
我不知道该怎么做。因为我不能做之前的条件,如果我已经在弹出窗口内,那就太晚了
发布于 2013-04-27 00:50:01
我最终使用过滤器对其进行过滤,如下所示
$('.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') + '" />';
}
});发布于 2013-04-27 00:46:30
您可以使用类body遍历所有项,并在匹配特定条件的情况下添加一个新类(例如imgbody),而不是在弹出窗口中执行此操作。然后,只为该类创建弹出效果。
所以:
$('.body').each(function(index, elem) {
if (/(jpg|gif|png)$/.test($(elem).attr('href')))
$(elem).addClass("imgbody");
});
$(".imgbody").popover({ ...https://stackoverflow.com/questions/16240934
复制相似问题