<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1 id="app" style="font-size: 20px; color: pink">hao</h1>
<h1 id="app1" style="font-size: 20px; color: pink">hao</h1>
<input type="text" id="inp" placeholder="123">
<script type="text/javascript">
var app=document.getElementById('app');
var app1=document.getElementById('app1');
var inp=document.getElementById('inp');
//监听点击
//使用匿名函数
app.onclick=function() {
app.style.fontSize='50px';
}
app.onclick=function() {
app.style.fontSize='100px';//设置一样的话会覆盖前面的属性
}
//监听双击
function fn() {
app1.setAttribute('style','font-size: 30px; color: red');
}
app1.ondblclick=fn;//不能加括号
//监听移入
app.onmouseenter=function() {
// document.write('onmouseenter');
app.innerHTML='onmouseenter';
}
//监听移出
app.onmouseleave=function() {
app.innerHTML='onmouseleave';
}
//输入框获取焦点(鼠标点击后)
inp.onfocus=function() {
inp.placeholder='please';
}
//输入框失去焦点
inp.onblur=function() {
inp.style.fontSize='20px';
inp.style.border='1px solid green';
}
</script>
</body>
</html>
<Dom事件>
于 2020-12-15 21:07:09 首次发布