1 $("p").hover(function(){ 2 $("p").css("background-color","yellow"); 3 },function(){ 4 $("p").css("background-color","pink"); 5 });
定義和用法
hover() 方法規定當鼠標指針懸停在被選元素上時要運行的兩個函數。
方法觸發 mouseenter 和 mouseleave 事件。
注意: 如果只指定一個函數,則 mouseenter 和 mouseleave 都執行它。
語法
$(
selector).hover(
inFunction,outFunction)
調用:
$( selector ).hover( handlerIn, handlerOut )
等同以下方式:
$( selector ).mouseover( handlerIn ).mouseout( handlerOut );
注意:如果只規定了一個函數,則它將會在 mouseover 和 mouseout 事件上運行。
調用:
$(selector).hover(handlerInOut)
等同於:
$( selector ).on( "mouseover mouseout", handlerInOut );