jQuerymouseover()method 是一種內置方法,當鼠標指針移動到所選元素上時該方法起作用。
用法:
$(selector).mouseover(function)
參數:此方法接受可選的單參數函數。該參數用於指定調用 mouseover 事件時要運行的函數。
示例 1:此示例說明了mouseover()方法的使用。
HTML
<!DOCTYPE html>
<html>
<head>
<title>The mouseover Method</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<!-- jQuery code to show the working of this method -->
<script>
$(document).ready(function () {
$("p").mouseover(function () {
$("p").css("background-color", "lightgreen");
});
});
</script>
<style>
body {
width: 280px;
padding: 40px;
height: 30px;
border: 2px solid green;
font-weight: bold;
font-size: 20px;
}
</style>
</head>
<body>
<!-- move over this text to see the change -->
<p>Welcome to GeeksforGeeks!</p>
</body>
</html>
輸出:
示例 2:在這個例子中,當鼠標移動到段落上時會出現一個彈出窗口。
HTML
<!DOCTYPE html>
<html>
<head>
<title>The mouseover Method</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<!-- jQuery code to show the working of this method -->
<script>
$(document).ready(function () {
$("p").mouseover(function () {
alert("Mouse moved over this paragraph");
});
});
</script>
<style>
body {
width: 280px;
padding: 40px;
height: 30px;
border: 2px solid green;
font-weight: bold;
font-size: 20px;
}
</style>
</head>
<body>
<!-- move over this text and pop-up will come out -->
<p>Welcome to GeeksforGeeks!</p>
</body>
</html>
輸出:
相關文章:
相關用法
- JQuery mouseover()用法及代碼示例
- JQuery mouseout()用法及代碼示例
- JQuery mousedown()用法及代碼示例
- JQuery mouseenter()用法及代碼示例
- JQuery mouseleave()用法及代碼示例
- JQuery mousemove()用法及代碼示例
- JQuery mouseup()用法及代碼示例
- JQuery merge()用法及代碼示例
- JQuery makeArray()用法及代碼示例
- JQuery map()用法及代碼示例
- JQuery andSelf()用法及代碼示例
- JQuery change()用法及代碼示例
- JQuery each()用法及代碼示例
- JQuery end()用法及代碼示例
- JQuery fadeOut()用法及代碼示例
- JQuery height()用法及代碼示例
- JQuery innerHeight()用法及代碼示例
- JQuery keydown()用法及代碼示例
- JQuery keypress()用法及代碼示例
- JQuery next()用法及代碼示例
- JQuery nextAll()用法及代碼示例
- JQuery parent()用法及代碼示例
- JQuery parents()用法及代碼示例
- JQuery prev()用法及代碼示例
- JQuery prevAll()用法及代碼示例
注:本文由純淨天空篩選整理自kundankumarjha大神的英文原創作品 jQuery mouseover() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。