focus()方法觸發(fā)焦點(diǎn)事件,或附加一個(gè)函數(shù)以在焦點(diǎn)事件發(fā)生時(shí)運(yùn)行。
焦點(diǎn)事件在元素獲得焦點(diǎn)時(shí)發(fā)生(通過(guò)單擊鼠標(biāo)或通過(guò)“選項(xiàng)卡導(dǎo)航”對(duì)其進(jìn)行選擇)。
該方法通常與blur()方法一起使用。
觸發(fā)所選元素的焦點(diǎn)事件:
$(selector).focus()
將函數(shù)附加到焦點(diǎn)事件:
$(selector).focus(function)
觸發(fā)<input>的焦點(diǎn)事件:
$(document).ready(function(){ $("input").focus(); });測(cè)試看看?/?
將函數(shù)附加到焦點(diǎn)事件(焦點(diǎn)事件在<input>字段獲得焦點(diǎn)時(shí)發(fā)生):
$("input").focus(function(){ $(this).next("span").css("display", "inline").fadeOut(2000); });測(cè)試看看?/?
將函數(shù)附加到焦點(diǎn)事件(焦點(diǎn)事件在<input>字段獲得焦點(diǎn)時(shí)發(fā)生):
$("input").focus(function(){ $(this).css("background", "white"); });測(cè)試看看?/?
參數(shù) | 描述 |
---|---|
function | 每次焦點(diǎn)事件觸發(fā)時(shí)執(zhí)行的函數(shù) |