JS中onfocus()事件,onblur()事件,onload()事件1. onfocus 事件在对象获得焦点时发⽣。
实例:
<html>
<head>
<script type="text/javascript">
function setStyle(x)
{
}
</script>
</head>
<body>
First name: <input type="text" onfocus="setStyle(this.id)" id="fname"/><br />
Last name: <input type="text" onfocus="setStyle(this.id)" id="lname"/>
</body>
</html>
结果:当⽤⿏标点击input窗⼝的时候 input背景颜⾊为黄⾊
2. onblur 事件会在对象失去焦点时发⽣;
实例:
<html>
<head>
<script type="text/javascript">
function upperCase()
{
var ElementById("fname").value
}
</script>
</head>
<body>
输⼊您的姓名:<input type="text" id="fname" onblur="upperCase()"/>
</body>
</html>
结果:在input窗⼝中输⼊⼩写的英⽂当input失去焦点的时候将刚输⼊的input的value内容转成⼤写input绑定onblur事件
例: