【问题标题】:Bootstrap popover replicating code引导弹出窗口复制代码
【发布时间】:2014-03-06 12:28:43
【问题描述】:

我正在使用 raty 来执行评分功能,并在弹出框内显示它。

问题是我第一次点击链接时,它正确地创建了星星,但是当我第二次点击时,星星被复制了,所以它弹出了 10 颗星星而不是 5 颗。

$('#member1').popover({
    html: true,
    placement: 'bottom',
    content: function() {
        return $($(this).data('contentwrapper')).html();
    }
}).click(function() {
    $('.star').each(function(el) {
        $(this).raty({
            starOff : 'http://wbotelhos.com/raty/lib/images/star-off.png',
            starOn : 'http://wbotelhos.com/raty/lib/images/star-on.png',
            start: $(this).attr('data-rating')
        });
    });
});

我在这个fiddle 中复制了错误。

谁能告诉我如何解决这个问题,因此只显示 5 颗星?

谢谢!!!!

【问题讨论】:

    标签: javascript jquery twitter-bootstrap popover rate


    【解决方案1】:

    我对 raty 并不太熟悉,但您似乎需要在第二次或第三次运行代码之前销毁现有的。

    $(this).raty('destroy');
    

    类似的东西,检查比率文档以了解确切的实施

    【讨论】:

      【解决方案2】:

      请查看此代码

      $('#member1').popover({
              html: true,
              placement: 'bottom',
              content: function() {
                  return $($(this).data('contentwrapper')).html();
              }
          }).click(function() {
              $('.star').each(function(el) {
                $(this).raty('destroy');
                  $(this).raty({
      
                      starOff : 'http://wbotelhos.com/raty/lib/images/star-off.png',
                      starOn : 'http://wbotelhos.com/raty/lib/images/star-on.png',
                      start: $(this).attr('data-rating')
                  });
      
              });
          });
      

      演示:http://jsfiddle.net/x9WhH/3/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多