1

这是我的弹出框代码:

$(function () {
  $('.popover').popover({ 
    html : true,
    content: console.log($(this).id) ,
    placement:  'top'
  });
});

这是我的html代码:

<a class="popover" id="CHANGING-NUMBER(4,5,6,....)"> Foo </a>

但控制台中显示的输出仅显示“未定义”。如何获取显示弹出框的锚的 ID?

4

1 回答 1

2

那时this不指代元素。您需要将 id 单独传递给每个元素:

$(function () {  
  $('.popover').each( function() {
    $(this).popover({ 
        html : true,
        content: this.id,
        placement: 'top'
    });
  });
});
于 2013-08-04T20:31:55.157 回答