js 鼠标移上去修改style属性
时间:2023年10月23日
/来源:网络
/编辑:佚名
演示效果
鼠标移上去,颜色显示为红色,鼠标移开,颜色显示为黑色。
获取id对象:document.getElementById()
鼠标移上去:onmouseover
鼠标移开:onmouseout
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#box1{
height: 30px;
text-align: center;
font: 30px/30px "楷体";
}
</style>
</head>
<body>
<div id="box1">
锣鼓一响,黄金万<span id="span">两</span>
</div>
<script>
document.getElementById("box1").onmouseover = function(){
document.getElementById("span").style.color = "red";
};
document.getElementById("box1").onmouseout = function(){
document.getElementById("span").style.color = "#000";
};
</script>
</body>
</html>
鼠标移上去,颜色显示为红色,鼠标移开,颜色显示为黑色。
获取id对象:document.getElementById()
鼠标移上去:onmouseover
鼠标移开:onmouseout
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#box1{
height: 30px;
text-align: center;
font: 30px/30px "楷体";
}
</style>
</head>
<body>
<div id="box1">
锣鼓一响,黄金万<span id="span">两</span>
</div>
<script>
document.getElementById("box1").onmouseover = function(){
document.getElementById("span").style.color = "red";
};
document.getElementById("box1").onmouseout = function(){
document.getElementById("span").style.color = "#000";
};
</script>
</body>
</html>
新闻资讯 更多
- 【建站知识】查询nginx日志状态码大于400的请求并打印整行04-03
- 【建站知识】Python中的logger和handler到底是个什么?04-03
- 【建站知识】python3拉勾网爬虫之(您操作太频繁,请稍后访问)04-03
- 【建站知识】xpath 获取meta里的keywords及description的方法04-03
- 【建站知识】python向上取整以50为界04-03
- 【建站知识】scrapy xpath遇见乱码解决04-03
- 【建站知识】scrapy爬取后中文乱码,解决word转为html 时cp1252编码问题04-03
- 【建站知识】scrapy采集—爬取中文乱码,gb2312转为utf-804-03