4

JavaScript 事件 onblur 与 onfocus 区别

 2 years ago
source link: https://segmentfault.com/a/1190000040896671
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

JavaScript 事件 onblur 与 onfocus 区别

发布于 今天 15:32

一、onblur

1.1 说明

onblur属性在元素失去焦点时触发,onblur常用于表单验证代码(例如用户离开表单字段)。

1.2 示例

<input type="text" name="" id="" onblur="javascript:alert('onblur');">

二、onfocus

2.1 说明

onfocus属性在元素获得焦点时触发,onfocus常用于<input>、<select>以及

2.2 示例

<!--点击后因为不断onfocus会不断弹出,可以直接关闭浏览器标签页终止-->
<input type="text" name="" id="" onfocus="javascript:alert('onfocus');">

版权声明

本博客所有的原创文章,作者皆保留版权。转载必须包含本声明,保持本文完整,并以超链接形式注明作者后除和本文原始地址:https://blog.mazey.net/428.html


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK