JavaScript&jQuery.焦点事件
焦点事件
焦点事件,当一个元素(比如链接或表单)得到或失去焦点时发生。
事件有:
- focus,获得焦点时触发。
- blur,失去焦点时触发。
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>失去焦点后转大写</h1>
<p>输入字符,可以转换成大小写</p>
<input id="s">
<br><br>
<button>点击我,input失去焦点</button>
<p id="out">
<script>
var EL = document.getElementById('s');
EL.addEventListener('dlur',checkkey,false);
function checkkey(e){
var str = EL.value;
alert("你输入的字符是:"+str);
out.textConteent=str.toUpperCase();
}
</script>
</p>
</body>
</html>