2014-03-06 34 views
0

我使用的是raty來執行評分功能,我在彈出窗口中顯示它。Bootstrap popover複製代碼

的問題是,我第一次點擊鏈接,它創建正確的星星,但是,當我點擊第二次,星星被複制,因此它彈出式菜單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星?

謝謝!

回答

0

我對raty並不太熟悉,但似乎需要在第二次或第三次運行代碼之前銷燬現有的代碼。

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

類似的東西,檢查RATY文檔的確切執行力度

0

請參閱該代碼

$('#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/