3

我想应用这个弹出框

$('.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'))

我不知道该怎么做..因为我以前不能做这个条件,如果我已经在弹出框里面,那就太晚了

4

2 回答 2

2

除了在弹出窗口中执行此操作,您可以遍历所有具有类的项目,并在它匹配某些条件时body添加一个新类(例如)。imgbody然后,您仅为该类创建弹出框。

所以:

$('.body').each(function(index, elem) {
  if (/(jpg|gif|png)$/.test($(elem).attr('href')))
     $(elem).addClass("imgbody");
});
$(".imgbody").popover({ ...
于 2013-04-26T16:46:29.810 回答
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') + '" />';
             }
            });
于 2013-04-26T16:50:00.980 回答