当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 老生常谈onBlur事件与onfocus事件(js)

老生常谈onBlur事件与onfocus事件(js)

2019年07月29日  | 移动技术网IT编程  | 我要评论

onfocus事件就是当光标落在文本框中时发生的事件。

onblur事件是光标失去焦点时发生的事件。

可以编如下例子

1.html

<html> 
<head> 
<title>使用onblur事件处理程序</title> 
</head> 
<body bgcolor="lavender"> 
<form name="f1"> 
<input type=text name=text1 value="1111onblur_green" onblur="(document.bgcolor='green')"> 
<input type=text name=text2 value="2222onblur_black" onblur="(document.bgcolor='black')"> 
<input type=text name=text2 value="3333onblur_yellow" onblur="(document.bgcolor='yellow')"> 
<br>
<p>
<input type=text name=text3 value="4444onfocus_blue" onfocus="(document.bgcolor='blue')"> 
<input type=text name=text4 value="5555onfocus_red" onfocus="(document.bgcolor='red')">
<input type=text name=text4 value="6666onfocus_orange" onfocus="(document.bgcolor='orange')">
</form> 
</body> 
</html>

还有以下例子

2.html

<!-- 文件说明:onfocus事件 -->
 <!-- ------------------------------ -->
 <html>
 <head>
 <title>onfocus事件</title>
 </head>
 <body>
 <form>

 <input type="text" name="test1" value="test1" onclick=alert("可以关掉!")> 
 <input type="text" name="test1" value="test1" onblur=alert("可以关掉aaaaaaa!")>

 <input type="text" name="test1" value="test1" onclick=alert("可以关掉bbbbbbbbb!")> 
 <input type="text" name="test2" value="一按我就无法关掉了,haha" onfocus=alert("我成为了输入焦点!")>
 </form>
 </body>
 </html>

以上这篇老生常谈onblur事件与onfocus事件(js)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网