onchange
当你离开输入框后,函数将被触发,将小写字母转为大写字母。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function fn(id) {
let tx = document.getElementById(id)
tx.value = tx.value.toUpperCase()
}
</script>
</head>
<body>
输入你的名字: <input type="text" onchange="fn(this)" id="name">
<p>离开输入框后函数将被触发,将小写字母转为大写字母</p>
</body>
</html>