这是我的 .js 文件中的内容:
function starClick1() {
document.getElementById=("RatingStars").src="../images/Stars1";
}
function starClick2() {
document.getElementById=("RatingStars").src="../images/Stars2";
}
function starClick3() {
document.getElementById=("RatingStars").src="../images/Stars3";
}
在 .html 文件中我放了这个:
<div id="RatingStars">
<img onmousemove="imageSwitch1()" onclick="starClick1()" onmouseout ="imageSwitchOut1()" id="star1" height="14px" src="../images/starWhite.png">
<img onmousemove="imageSwitch2()" onclick="starClick2()" onmouseout ="imageSwitchOut2()" id="star2" height="14px" src="../images/starWhite.png">
<img onmousemove="imageSwitch3()" onclick="starClick3()" onmouseout ="imageSwitchOut3()" id="star3" height="14px" src="../images/starWhite.png">
</div>
PS:其他函数与我的问题没有任何关系(我认为)。
最佳答案
replaceWith()
用另一个元素替换元素:
var otherElement = $('<img />', {src: 'image.png'});
$('#RatingStars').replaceWith(otherElement);
关于javascript - 如何为单个图像替换整个 Div 元素(其中包含其他元素)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19737266/