使用bootstrap和jquery更改弹出窗口的标题

使用bootstrap和jquery更改弹出窗口的标题

本文介绍了使用bootstrap和jquery更改弹出窗口的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是链接的html,即:

here's the html for the link, i.e.:

 <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'});;"没有骰子...谢谢.

yes, i'm calling .popover() to initialize and the popover works just fine. i can get the content to update with no problem. just not the title. i've tried "prev.data('title','new title')" and even tried to re-init "prev.popover({title:'new title'});" with no dice... thanks.

 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');
}

推荐答案

考虑猫被剥皮了!

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

Here's the deal. It appears that in the bootstrap.js file there is no method for getTitle() even though it's calling. So I added it. Enjoy.

/* 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
}

})


由于某种原因,我无法获取实际的"title"属性,因此,如果要更改它,则必须使用"data-title".

for some reason I can't grab the actual "title" attribute so you'll have to use "data-title" if you want to change it.

这篇关于使用bootstrap和jquery更改弹出窗口的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 05:48