jquery中的hover函數(shù)有2個參數(shù):1、必需參數(shù)“inFunction”,用于規(guī)定mouseenter事件發(fā)生時運行的事件處理函數(shù);2、可選參數(shù)“outFunction”,用于規(guī)定mouseleave事件發(fā)生時運行的事件處理函數(shù)。
本教程操作環(huán)境:windows7系統(tǒng)、jquery1.10.2版本、Dell G3電腦。
在jquery中,hover() 方法規(guī)定當鼠標指針懸停在被選元素上時要運行的兩個函數(shù)。
該方法會觸發(fā) mouseenter 和 mouseleave 事件。
因此,hover函數(shù)接受兩個參數(shù):一個必需,一個可省略。
語法:
$(selector).hover(inFunction,outFunction)
參數(shù) | 描述 |
---|---|
inFunction | 必需。規(guī)定 mouseenter 事件發(fā)生時運行的函數(shù)。 |
outFunction | 可選。規(guī)定 mouseleave 事件發(fā)生時運行的函數(shù)。 |
注意:如果只規(guī)定了一個函數(shù),則它將會在 mouseenter 和 mouseleave 事件上運行。
示例:當鼠標指針懸停在上面時,改變 <p> 元素的背景顏色
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("p").hover(function() { $("p").css("background-color", "yellow"); }, function() { $("p").css("background-color", "pink"); }); }); </script> </head> <body> <p>鼠標移動到該段落。</p> </body> </html>
【推薦學習:jQuery視頻教程、web前端視頻】