【问题标题】:how do you get the $this properties/attribute of bootstrap to be used as parameters你如何让 $this 的引导程序的属性/属性用作参数
【发布时间】:2013-03-27 02:51:58
【问题描述】:

如何获取 twitter 引导参数值的弹出框的 this 属性,就像我需要获取列表项属性,即要在引导弹出框标题中使用的 data-boothtype 一样?数据标题还不够

HTML

<li class="booth" data-boothnumber="46" data-boothtype="prime" style="left: 240px; top: 30px;">46</li>

JS

$('.booth').popover({title: this.data-boothtype + "'s Booth", content: "test", placement: "right", callback:function(){ console.log(this)}});

PS: 回调函数是来自Callback function after tooltip / popover is created with twitter bootstrap?的测试单元

$.fn.popover.Constructor.prototype.show = function () {
  tmp.call(this);
  if (this.options.callback) {
    this.options.callback();
  }
}

编辑 好的,这里缩小范围:http://jsfiddle.net/tHHQ6/

【问题讨论】:

  • this.data-boothtype 甚至都不是有效的 JavaScript 代码。首先掌握最基本的知识很重要......
  • 哦,是的,无论如何,谢谢你,只是调用对象属性的想法......也许我错过了很多基础知识......

标签: javascript twitter-bootstrap javascript-objects


【解决方案1】:

你需要做的

$('.booth').each(function(i, v){
    var $el = $(v);
    $el.popover({
        title: 'test' + $el.data('boothnumber'), 
        content: "test", 
        placement: "right"
    });
});

演示:Fiddle

【讨论】:

  • 我从没想过递归调用 dom 并且每个给定的属性 w/c 都可以直接访问是一个好主意,无论如何,谢谢你,这里有一个赞成 :)
  • 在这种情况下这是唯一的方法,因为必须动态找到标题
【解决方案2】:

使用 JQuery,您可以执行以下操作:

$('.booth').data('boothnumber')

请参阅here 获取 .data() api

【讨论】:

  • 这个问题可能会产生误导,对此表示抱歉,无论如何谢谢。我只是希望在引导弹出窗口标题中使用当前($this)数据......在这里让我帮你帮助我:) jsfiddle.net/tHHQ6
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-18
  • 2013-01-30
相关资源
最近更新 更多