返回值:jQueryblur(handler(eventObject))
Bind an event handler to the "blur" JavaScript event, or trigger that event on an element.
-
1.0 新增blur(handler(eventObject))
handler(eventObject) (Function) 每当事件触发时执行的函数。 -
1.4.3 新增blur([eventData], handler(eventObject))
eventData (Object) 可选参数,将要传递给事件处理函数的数据映射。handler(eventObject) (Function) 每当事件触发时执行的函数。 -
1.0 新增blur()
This method is a shortcut for .bind('blur', handler)
in the first variation, and .trigger('blur')
in the second.
The blur
event is sent to an element when it loses focus. Originally, this event was only applicable to form elements, such as <input>
. In recent browsers, the domain of the event has been extended to include all element types. An element can lose focus via
keyboard commands, such as the Tab key, or by mouse clicks elsewhere on the page.
For example, consider the HTML:
<form> <input id="target" type="text" value="Field 1" /> <input type="text" value="Field 2" /> </form> <div id="other"> Trigger the handler </div> The event handler can be bound to the first input field: $('#target').blur(function() { alert('Handler for .blur() called.'); });
Now if the first field has the focus and we click elsewhere, or tab away from it, the alert is displayed:
Handler for .blur() called.
We can trigger the event when another element is clicked:
$('#other').click(function() { $('#target').blur(); });
After this code executes, clicks on Trigger the handler will also alert the message.
The blur
event does not bubble in Internet Explorer. Therefore, scripts that rely on event delegation with the blur
event will not work consistently across browsers.
示例:
To trigger the blur event on all paragraphs:
jQuery 代码:
$("p").blur();