このリンクでクライアントの 1 つに提供されている 5 つ星評価システム (jquery と PHP に基づく) を使用しました。現在、ユーザーが製品を評価した場合、それらの数の星が強調表示されたままになることを望んでいますが、現在のシナリオでは、ユーザーがマウスを離すと、星は強調表示されたままになりません。
私はたくさん試しましたが、mouseout
関数は関数と競合しclick
ます。これまでのところ、私はこれを使用しています:
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
機能する必要があります。つまり、星の強調表示を解除します。
助けてください、私は必死です。