-3

我正在使用 jQuery 操作链接的 data-complete-text 属性。我的代码看起来像这样。

var complete =  _self.attr("data-complete-text");

_self.attr("data-complete-text","<span class='symbol-done-tick'></span><span class='acheived-text'>"+complete+"</span>");

那就是我将 html 跨度分配给该属性以获得所需的效果,并且它工作正常。我的意思是,跨度被正确插入,但我在这些跨度中指定的 CSS 类没有任何效果。我不知道为什么。帮帮我。

4

1 回答 1

1

如果您尝试设置data-complete-text以便 BootstrapButton将使用它,则在设置data-complete-text属性后,您还必须设置按钮的状态:

_self.button('complete');

文档(例如它)并没有说它在那里支持 HTML,但它似乎在我的测试中有效:Live Example | 来源

HTML:

<button id="target" type="button" class="btn btn-primary" data-loading-text="Loading...">Original Text</button>

JavaScript:

jQuery(function($) {

  // Get the button
  var _self = $("#target");

  // Set the attribute
  _self.attr("data-complete-text",
             "<span class='foo'>Complete</span>");

  // Wait for click
  _self.one("click", function() {

    _self.button('complete');
  });

});

在上面,当您将按钮状态设置为 时,内部的foo类起作用。spandata-complete-text'complete'

于 2012-11-02T07:26:08.353 回答