HTML学习1-Dom之事件绑定

时间:2022-09-29 21:10:06

事件:

1、注册事件

a. <div onxxxx=””></div>

b. document  .onxxxx= function()  //找到这个标签

2、this,触发当前事件的标签

3、event ,触发当前标签的事件内容

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div onmouseover="Func(this)" onmouseout="Func1(this)"> 123</div>
<input type="text" onkeydown="Down(this,event);">
<script>
function Down(ths,e) {
console.log(e.keyCode); }
function Func(ths) {
ths.style.color = 'red';
} function Func1(ths) {
ths.style.color = 'black'; }
function
</script> </body>
</html>