我已經使用了五星評級系統(基於jQuery和PHP)的我的一個客戶提供in this link。現在,他們希望如果用戶對產品進行評價,那麼許多恆星應該保持高亮顯示,但在目前的情況下,一旦用戶移出鼠標,恆星不再高亮顯示。PHP五星評級 - 星星不繼續點擊
我已經嘗試了很多,但與click
功能mouseout
功能衝突。到目前爲止,我使用這個:
HTML
<div id="r1" class="rate_widget">
<div class="star_1 ratings_stars" id="1"></div>
<div class="star_2 ratings_stars" id="2"></div>
<div class="star_3 ratings_stars" id="3"></div>
<div class="star_4 ratings_stars" id="4"></div>
<div class="star_5 ratings_stars" id="5"></div>
<div class="total_votes">vote data</div>
</div>
JS - 我有這個調整了我自己,但沒有成功的一點。
$(document).ready(function() {
$('.ratings_stars').hover(
// Handles the mouseover
function() {
$(this).prevAll().andSelf().addClass('ratings_over');
$(this).nextAll().removeClass('ratings_vote');
},
// Handles the mouseout
function() {
$(this).prevAll().andSelf().removeClass('ratings_over');
// can't use 'this' because it wont contain the updated data
set_votes($(this).parent());
}
);
// This actually records the vote
$('.ratings_stars').bind('click', function() {
var star = this;
var widget = $(this).parent();
count = $(star).attr('id');
var clicked_data = {
clicked_on : $(star).attr('class'),
widget_id : $(star).parent().attr('id')
};
$.post(
'ratings.php',
clicked_data,
function(INFO) {
widget.data('fsr', INFO);
set_votes(widget);
//$(this).prevAll().andSelf().addClass('ratings_over');
// $(this).nextAll().removeClass('ratings_vote');
$('#msg').hide().html("you have rated this product with "+count+" stars.").fadeIn(1500);
//alert("you have rated this product with"+count);
},
'json'
);
});
});
function set_votes(widget) {
var avg = $(widget).data('fsr').whole_avg;
var votes = $(widget).data('fsr').number_votes;
var exact = $(widget).data('fsr').dec_avg;
window.console && console.log('and now in set_votes, it thinks the fsr is ' + $(widget).data('fsr').number_votes);
$(widget).find('.star_' + avg).prevAll().andSelf().addClass('ratings_vote');
// $(widget).find('.star_' + avg).nextAll().removeClass('ratings_vote');
$(widget).find('.total_votes').text(votes + ' votes recorded (' + exact + ' rating)');
}
在當前形勢下,一旦明星們點擊它顯示了更新的平均得分從PHP計算腳本返回。
我希望星星在點擊後甚至在mouseout
之後保持高亮,如果沒有點擊它們,mouseout
應該起作用,即它不起作用。
請幫幫忙,我絕望。
這聽起來像一些相關的'CSS' – MISJHA 2013-05-09 12:51:17
@MISJHA沒有的東西,它的JS只因爲它是處理除了點擊功能的鼠標移開功能了。 – coder101 2013-05-09 12:53:36
只是一個想法,將「數據庫」等級更改爲差異類別不是更容易,該類別是每個星級元素的基礎。然後嚴格地將懸停類用於懸停,最後當用戶做出選擇時,設置一個選擇的類,在其CSS中使用'!important'來覆蓋所有其他可用的類。 – SpYk3HH 2013-05-09 12:55:29