gpt4 book ai didi

JavaScript 影响悬停时的 div

转载 作者:行者123 更新时间:2023-12-02 17:02:32 24 4
gpt4 key购买 nike

大家好,我刚刚编写了这段代码。我想要的只是将光标悬停在该按钮上并影响其右侧的 div。 我现在遇到的问题是我无法链接任何图像。只有颜色。但我不需要颜色。我知道这很简单,但我现在忘记了。

<script> function chbg(color){document.getElementById('container2').style.backgroundColor=color;}
</script>

<button id="button1" onmouseover="chbg('red')" onmouseout="chbg('whitesmoke')"></button>

最佳答案

<script>
function chimage(url) {
document.getElementById('container2').style.backgroundImage = 'url('+url+')';
}
</script>

<button id="button1" onmouseover="chimage('/path/to/hoverimage.jpg')" onmouseout="chimage('/path/to/plainimage.jpg');"></button>

关于JavaScript 影响悬停时的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25569111/

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