【发布时间】:2014-05-25 14:11:59
【问题描述】:
我有五颗星,当鼠标悬停时,鼠标悬停的星和这颗星之前的星星必须更改为不同的颜色。 onclick 事件也必须如此。下面是 HTML 代码。我已经为此尝试了一些CSS。但我不明白该怎么做?如何获取 CSS 代码?
<script type="text/javascript">
$(document).ready(function(){
$("#images img").click(function(){
$(this).addClass('active');
var va = $(this).attr("name");
$("#result_value").text(va);
});
$("#images img").mouseover(function(){
});
});
$(document).on('click','#images img',function(e) {
var va = $(this).attr("name");
$.ajax({
data:' va='+va,
type: "post",
url: "insertmail.php",
success: function(va){
alert("Data Save: " + va);
}
});
});
</script>
<style>
.clr:hover{
background-color:#FFD700;
}
.active{
background-color:#FFD700;
}
</style>
</head>
<body>
<div class="images" id="images">
<form name="imagediv" id="imagediv" method="post">
<img src="star1.png" class="one clr" alt="Number 1" name="1" width="42" height="42">
<img src="star2.png" class="two clr" alt="Number 1" name="2" width="42" height="42">
<img src="star3.png" class="three clr" alt="Number 1" name="3" width="42" height="42">
<img src="star4.png" class="four clr" alt="Number 1" name="4" width="42" height="42">
<img src="star5.png" class="five clr" alt="Number 1" name="5" width="42" height="42">
</form>
</div>
<div class="result_value" id="result_value" ></div>
</body>
【问题讨论】:
-
如果您打算使用图像。尝试使用图像精灵。 css-tricks.com/css-sprites-with-inline-images
标签: javascript jquery html css