经过本节学习熟悉撑握了对控件作鼠标事件触发,改变控件风格属性

原创 2018-12-03 19:48:26 225
摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script type="text/javascri
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
//改变文本框背景颜色
function yellow(a)
{
a.style.background = "red";
}
//改变div距形背景颜色
function myfovus(x)
{
x.style.background="red";
}
//改变div位置
function move(y){
y.style.marginLeft="150px";
}
</script>
<input type="text" value="点我变红色:" onfocus="myfovus(this)"><br><br>

<div style="width:100px;height: 100px;background:yellow;border:1px solid #000;" onmouseout ="yellow(this)">鼠标移开我会变色:</div><br><br>

<div style="width:100px;height:100px;background:#ccc;border:1px solid #000;margin-left:10px;" onclick="move(this)">按键盘我会跑哦</div>
</body>
</html>

学会了对控件触发鼠标事件后调用js自定义函数,在调用函数的同时向自定义函数传了this参数,可以在函数内部对自身控件属性改变设置等。。

批改老师:天蓬老师批改时间:2018-12-04 09:09:04
老师总结:事件,除了可以直接以属性方式添加到标签上之外,其实最常用的是通过系统函数: addEventListener()来添加,有空了解一下

发布手记

热门词条