当元素失去焦点时运行JavaScript


134

我有一个标准的HTML输入,当它失去焦点时,我想运行JavaScript代码。不幸的是,我的Google搜索没有显示如何执行此操作。

为了清楚起见,我正在寻找一种方法来做到这一点:

<input type="text" name="name" value="value" onlosefocus="alert(1);"/>

Answers:


258

怎么样onblur事件:

<input type="text" name="name" value="value" onblur="alert(1);"/>


37

您要使用onblur事件。

<input type="text" name="name" value="value" onblur="alert(1);"/>


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.