6

这是链接的html,即:

 <a href="javascript:void(0);" style="font-size: 3em; color: #222" class="popover-test" id="directNavPrev" data-title="Previous Result Row" data-content="Previous Result Row">
&laquo;</a>

是的,我正在调用 .popover() 进行初始化,并且弹出框工作得很好。我可以毫无问题地更新内容。只是不是标题。我尝试过“prev.data('title','new title')”,甚至尝试重新初始化“prev.popover({title:'new title'});” 没有骰子...谢谢。

 function SetDirectNavigationPlaceholder() {
    //debugger;
    var item = $("#movementType :selected").val();
    var direct = $('#directNavigation');
    var prev = $('#directNavPrev');
    var next = $('#directNavNext');
    switch (item) {
        case "result":
            $('#bookTypeSection').addClass('hide');
            direct.val('Result Row from 1 - 150');
            prev.attr('data-title', "Previous Result Row");
            next.attr('data-title', "Next Result Row");
            prev.attr('data-content', "Check it! this will contain the information for the previous result<table><tr><td>blah</td><td>blah</td></tr><tr><td>blah</td><td>blah</td></tr><tr><td>blah</td><td>blah</td></tr><tr><td>blah</td><td>blah</td></tr></table>");
            next.attr('data-content', "Check it! this will contain the information for the next result<table><tr><td>blah</td><td>blah</td></tr></table>");
            break;
        case "instrument":
            $('#bookTypeSection').addClass('hide');
            direct.val('Instrument #');
            prev.attr('data-title', "Previous Instrument #");
            next.attr('data-title', "Next Instrument #");
            prev.attr('data-content', "Check it! this will contain the information for the previous <b>instrument</b><table><tr><td>blah</td><td>blah</td></tr></table>");
            next.attr('data-content', "Check it! this will contain the information for the next <b>instrument</b><table><tr><td>blah</td><td>blah</td></tr></table>");
            break;
        case "bookpage":
            $('#bookTypeSection').removeClass('hide');
            direct.val('Book/Page');
            prev.attr('data-title', "Previous Book/Page");
            next.attr('data-title', "Next Book/Page");
            prev.attr('data-content', "Check it! this will contain the information for the previous <b>book/page</b><table><tr><td>blah</td><td>blah</td></tr></table>");
            next.attr('data-content', "Check it! this will contain the information for the next <b>book/page</b><table><tr><td>blah</td><td>blah</td></tr></table>");
            break;
    }
    direct.css('color', '#aaa').not('#directNavigationHeader');
}
4

4 回答 4

21

最简单的方法是这个:

     var newTitle = "Here's my new title";
     $('#MyExample').attr('data-original-title', newTitle);

希望它有所帮助!

于 2013-07-25T17:30:28.500 回答
2

看起来 Twitter-bootstrap 并没有div为定位弹出窗口保留一个周围,所以通过更改标题来更改标题是不可能的。但是,这篇文章可能会有所帮助。

这是一个jsfiddle,你可以,呃,摆弄。

以及那些不能摆弄它的人的代码。:-)

HTML:

<div style="padding-top: 45px;">
    <a data-content="Original Content for Popover" data-original-title="Popover Title" data-placement="right" href="#" class="btn danger" id="popover-link" rel="popover">Rollover</a>
</div>​

JavaScript:

$('#popover-link').popover({title: function() {return 'new title';}});
$('#popover-link').attr("data-content", "New Content for Popover");
$('#popover-link').setTitle('new title');​
于 2012-07-25T19:42:32.277 回答
1

考虑一下那只猫皮!

这是交易。似乎在 bootstrap.js 文件中没有 getTitle() 的方法,即使它正在调用。所以我添加了它。享受。

/* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
 ========================================== */

Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
  constructor: Popover, setContent: function () {
  //debugger;

  var $tip = this.tip()
    , title = this.getTitle() // didn't exist
    , content = this.getContent()

  $tip.find('.popover-title')[this.isHTML(title) ? 'html' : 'text'](title)
  $tip.find('.popover-content > *')[this.isHTML(content) ? 'html' : 'text'](content)

  $tip.removeClass('fade top bottom left right in')
}

, hasContent: function () {
  return this.getTitle() || this.getContent()
}

 , getContent: function () {
  var content
    , $e = this.$element
    , o = this.options

  content = $e.attr('data-content')
    || (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)

  return content
}

 , getTitle: function () { // does now
  var title
    , $t = this.$element
    , n = this.options

  title = $t.attr('data-title')
    || (typeof n.title == 'function' ? n.title.call($t[0]) : n.title)

  return title
}

, tip: function () {
  if (!this.$tip) {
      this.$tip = $(this.options.template)
  }
  return this.$tip
}

})


由于某种原因,我无法获取实际的“标题”属性,因此如果要更改它,则必须使用“数据标题”。

于 2012-07-26T12:34:20.803 回答
1

这对我有用

$("#mylink").data()["bs.popover"].config.title = "New Ttile";
$("#mylink").data()["bs.popover"].config.content = "<p>New Content</p>";

或者

$("#mylink").data("bs.popover").config.title = "New Ttile";
$("#mylink").data("bs.popover").config.content = "<p>New Content</p>";
于 2019-09-24T21:00:55.510 回答