大家好,我刚刚编写了这段代码。我想要的只是将光标悬停在该按钮上并影响其右侧的 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/