事件
<button id="gos">点击</button>
<input type="text" placeholder="请输入用户名" id="btn">
<input type="text" placeholder="请输入密码" id="ptn">
<button>登录</button>
<script>
1.双击事件
var $gos = document.getElementById('gos')
$gos.ondblclick = (event) => {
alert('请输入用户')
}
2.键盘事件
var $btn = document.getElementById('btn')
$btn.onkeydown = (event) => {
console.log(event)
}
3.按下事件
var $ptn = document.getElementById('ptn')
$ptn.onkeypress = (event) => {
console.log(event)
if (event.charCode === 13) {
alert('正在登录')
}
}
绑定事件和点击元素
var $yeye = document.getElementById('yeye')
$yeye.onclick = (event) => {
alert('我是你爷爷', event.currentTarget)
alert('我是你爷爷', event.target)
}
输入框事件
var $pin = document.getElementById('pin')
$pin.oninput = (event) => {
console.log(event)
}