jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
focus
focus()

触发每一个匹配元素的focus事件。这个函数会调用执行绑定到focus事件的所有函数。

注意:这个函数不会调用相应元素的focus方法!如果需要通过代码来使一个元素获得焦点,必须使用DOM方法,例如:$("#myinput")[0].focus();

返回值:jQuery

示例:

$("p").focus();

HTML 代码:

<p onfocus="alert('Hello');">Hello</p>

结果:

alert('Hello');

 
focus()

Trigger the focus event of each matched element. This causes all of the functions that have been bound to thet focus event to be executed.

Note: This does not execute the focus method of the underlying elements! If you need to focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();

Return value: jQuery
Example:

 $("p").focus();  
Before:
 <p onfocus="alert('Hello');">Hello</p>  
Result:
 alert('Hello');