我有这个代码,鼠标悬停工作正常,但点击事件不起作用
HTML 代码:
<span class="rating">
<span class="rating1 rate" data-rating="1" title="1"><i class="icon-star-empty" ></i> </span>
<span class="rating2 rate" data-rating="2" title="2"><i class="icon-star-empty" ></i></span>
<span class="rating3 rate" data-rating="3" title="3"><i class="icon-star-empty" ></i></span>
<span class="rating4 rate" data-rating="4" title="4"><i class="icon-star-empty" ></i></span>
<span class="rating5 rate" data-rating="5" title="5"><i class="icon-star-empty" ></i></span>
查询
$(document).on('mouseover', '.rate', function () {
var rating = parseInt($(this).attr('data-rating'), 10);
var rate = rating + 1;
for (var j = 1; j < rate; j++)
{
$('.rating' + j).html('<i class="icon-star" title="' + j + '" data-rating="' + j + '"></i>');
}
for (var i = rate; i < 6; i++)
{
$('.rating' + i).html('<i class="icon-star-empty" title="' + i + '" data-rating="' + i + '"></i>');
}
});
$(document).on('click', '.rate', function () {
var rate = parseInt($(this).attr('data-rating'), 10);
alert(rate);
});