【发布时间】:2016-11-29 16:16:46
【问题描述】:
我目前正在制作留言簿,我想创建一个星级评分系统。但我被困住了!我只是无法修复星星,以便在我点击它们时它们保持黄色(凝胶)。
这是我目前的代码:
<div class="rating">
<p id="rating-paragraph">Rate</p>
<img id="stern1" src="pictures/durchsichtig.png" onmouseover="stern1.src='pictures/gelb.png'" onmouseout="stern1.src='pictures/durchsichtig.png'" alt="error"> <?php ?>
<img id="stern2" src="pictures/durchsichtig.png" onmouseover="stern1.src='pictures/gelb.png'; this.src='pictures/gelb.png'" onmouseout="stern1.src='pictures/durchsichtig.png'; this.src='pictures/durchsichtig.png'" alt="error">
<img id="stern3" src="pictures/durchsichtig.png" onmouseover="stern1.src='pictures/gelb.png'; stern2.src='pictures/gelb.png'; this.src='pictures/gelb.png' " onmouseout="stern1.src='pictures/durchsichtig.png';stern2.src='pictures/durchsichtig.png'; this.src='pictures/durchsichtig.png' " alt="error">
<img id="stern4" src="pictures/durchsichtig.png" onmouseover="stern1.src='pictures/gelb.png'; stern2.src='pictures/gelb.png'; stern3.src='pictures/gelb.png'; this.src='pictures/gelb.png' " onmouseout="stern1.src='pictures/durchsichtig.png';stern2.src='pictures/durchsichtig.png'; stern3.src='pictures/durchsichtig.png';this.src='pictures/durchsichtig.png' " alt="error">
<img id="stern5" src="pictures/durchsichtig.png" onmouseover="stern1.src='pictures/gelb.png'; stern2.src='pictures/gelb.png'; stern3.src='pictures/gelb.png'; stern4.src='pictures/gelb.png'; this.src='pictures/gelb.png' " onmouseout="stern1.src='pictures/durchsichtig.png';stern2.src='pictures/durchsichtig.png'; stern3.src='pictures/durchsichtig.png';stern4.src='pictures/durchsichtig.png'; this.src='pictures/durchsichtig.png' " alt="error">
</div>
还有css:
#stern1:hover, #stern2:hover, #stern3:hover, #stern4:hover, #stern5:hover{
cursor: pointer;
}
感谢您的宝贵时间,也许可以提供一些帮助或建议 :)
【问题讨论】:
-
欢迎来到 Stack Overflow!寻求代码帮助的问题必须包括在问题本身最好是在Stack Snippet 中重现它所需的最短代码。见How to create a Minimal, Complete, and Verifiable example
-
看起来您错过了一个单击事件,该事件将翻转图像以使星星保持亮起。你需要一个 onclick 或一个 JQuery $("#theId").on(click..... 让它去。An Example
标签: javascript jquery html css rating