javascript - 使用JS将鼠标悬停在文本上时更改正文背景图像
问题描述
基本上,当鼠标经过文本时,我正在尝试使用 JS 更改正文图像,在我向您展示的代码中,我现在使用一条线来更改正文颜色,但我不知道使它更改图像的语法,所以我试图为图像写一行,我评论了它,因为我不知道它是否正确,这是当鼠标悬停时工作改变颜色的代码。
<div class="row">
<div class="col-xl-4 offset-xl-4 text-center">
<p onmouseover="return bg1();"><a href="#" type="onmouseover" class="dimen">Sfondo 1</a></p>
<p onmouseover="return bg2();"><a href="#" type="onmouseover" class="dimen">Sfondo 2</a></p>
<p onmouseover="return bg3();"><a href="#" type="onmouseover" class="dimen">Sfondo 3</a></p>
<p onmouseover="return bg4();"><a href="#" type="onmouseover" class="dimen">Sfondo 4</a></p>
</div>
</div>
</body>
<script>
// document.getElementById("bgchange").style.backgroundImage= url(../media/battimani.jpg);
function bg1(){
document.getElementById("bgchange").style.backgroundColor = "#66ff66";
}
function bg2(){
document.getElementById("bgchange").style.backgroundColor = "#eb4034";
}
function bg3(){
document.getElementById("bgchange").style.backgroundColor = "#ebde34";
}
function bg4(){
document.getElementById("bgchange").style.backgroundColor = "#3440eb";
}
</script>
只复制了正文,你能告诉我如何正确编写脚本中的第一行注释吗?我想以 4 种不同的方式使用它,比如 4 种不同的颜色,谢谢 =)
ps:一周前刚开始学js,所以我的水平是basic basic
解决方案
尝试这个:
document.getElementById("bgchange").style.backgroundImage = "url(../media/battimani.jpg)";
推荐阅读
- javascript - 如何让类方法成为生成器函数?
- dart - 对 Bloc 使用单例
- java - Java swing metal JButton 焦点边框大小
- reactjs - 未捕获的错误:TypeError:未定义不是对象(评估“P.Constants”)
- charts - Google Charts API 面积图仅在注释中显示最大值和最小值
- python - Create separate models/tables that are subset of base model
- css - 轮播引导程序中的拉伸图像
- c# - Messenger Webview for Botframework V4
- jmeter - Jmeter - 同时运行多线程用户而不影响流量
- android - 在android中通过firebase进行Facebook登录时身份验证失败