У меня очень простая рейтинговая система. Проблема, с которой я сталкиваюсь, - это событие onclick, которое предполагает, чтобы изменить цвет звезды при нажатии.Изменение цвета звезды onClick - почему это не работает?
Я создал jsFiddle за то, что у меня есть.
HTML
<div class="rating">
<span id="five-stars" onclick="vote(5); return false;
document.getElementById('five-stars').style.color = '#ff6266'"
data-toggle="tooltip" data-placement="bottom" title="Rate 5 stars out of 5">
☆</span><span id="fout-stars" onclick="vote(4); return false;
document.getElementById('four-stars').style.color = '#ff6266'"
data-toggle="tooltip" data-placement="bottom" title="Rate 4 stars out of 5">
☆</span><span id="three-stars" onclick="vote(3); return false;
document.getElementById('three-stars').style.color = '#ff6266'"
data-toggle="tooltip" data-placement="bottom" title="Rate 3 stars out of 5">
☆</span><span id="two-stars" onclick="vote(2); return false;
document.getElementById('two-stars').style.color = '#ff6266'"
data-toggle="tooltip" data-placement="bottom" title="Rate 2 stars out of 5">
☆</span><span id="one-star" onclick="vote(1); return false;
document.getElementById('one-star').style.color = '#ff6266'"
data-toggle="tooltip" data-placement="bottom" title="Rate 1 star out of 5">
☆</span>
</div>
CSS
.rating {
color:#02dbdd;
font: 700 26px/normal 'Montserrat', sans-serif;
text-transform:uppercase;
display:block;
cursor:pointer;
margin-right:100px;
}
.rating {
unicode-bidi: bidi-override;
direction: rtl;
}
.rating > span {
display: inline-block;
position: relative;
width: 1.1em;
}
.rating > span:hover:before,
.rating > span:hover ~ span:before {
content: "\2605";
position: absolute;
}
Не знаю, почему он не изменится?
(The РТЛ вещь совершенно другая проблема, для решения ... лол)
JS прекратить выполнение, когда не удается найти '' 'vote (5)' '' function. Добавьте его, а затем он будет работать. – Grievoushead
Я добавил его, но это не работает, @Grievoushead –
также вам нужно удалить '' 'return statement''' из обработчика' '' onclick''' – Grievoushead