<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
//声明
function show(){
alert(1);
}
//调用
show();
</script>
</body>
</html>
————————————————————————————————————————————————————————————————————————————————————————————————--
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>鼠标点击事件</title>
<style>
div{
width: 200px;
height: 200px;
background: red;
}
</style>
</head>
<body>
<div id="box">
</div>
<!-- 在js中写动态-->
<script>
//1.获取元素.dom对象
var abox=document.getElementById("box");
//2.添加该div,并添加点击事件;
abox.onclick=function(){
abox.style.background="blue";
}
//3.悬浮
abox.onmouseover=function(){
abox.style.background="yellow";
abox.style.width="200px";
abox.style.height="200px";
}
abox.onmouseout=function(){
abox.style.background="red";
abox.style.width="333px";
abox.style.height="333px";
}
</script>
</body>
</html>
<!-- 在样式列表中的div中,background的属性不用加双引号。添加特效时加双引号-->
——————————————————————————————————————————————————————————————————————————————————————————————--
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>点击事件触发相关变化</title>
<style>
/* 标签选择器 */
div{
width:300px;
height: 300px;
background: pink;
}
</style>
</head>
<body>
<div id="box"></div>
<div id="box1"></div>
<script>
//1.获取元素对象;
var box=document.getElementById("box");
var box1=document.getElementById("box1");
//添加事件
box.onclick=function(){
//产生动态效果
box1.style.background="blue";
}
</script>
</body>
</html>
初始前端js
最新推荐文章于 2024-07-08 16:22:29 发布