gpt4 book ai didi

javascript - 如何为单个图像替换整个 Div 元素(其中包含其他元素)?

转载 作者:太空宇宙 更新时间:2023-11-04 14:23:20 25 4
gpt4 key购买 nike

这是我的 .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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com