jQuery | hover()及其示例

这个 悬停() 是jQuery中的一个内置方法,用于指定鼠标指针移动到选定元素上时要启动的两个函数。 语法:

null
$(selector).hover(Function_in, Function_out);

这里的选择器是选定的元素。 参数: 它接受下面指定的两个参数-

  • 功能_在: 它指定鼠标输入事件发生时要运行的函数。
  • 功能输出: 它是可选的,指定鼠标离开事件发生时要运行的函数。

返回值: 它返回选定元素的背景色效果。

显示hover()方法工作的jQuery代码:
代码#1:

< html >
< head >
< script src =
</ script >
< script >
<!-- jQuery code to show the working of hover() method -->
$(document).ready(function() {
$("p").hover(function() {
$(this).css("background-color", "green");
}, function() {
$(this).css("background-color", "yellow");
});
});
</ script >
< style >
p {
width: 55%;
height: 80px;
padding: 20px;
margin: 10px;
border: 2px solid green;
font-size: 50px;
}
</ style >
</ head >
< body >
<!--move the mouse in and out over this paragraph
and background color will change-->
< p >GeeksforGeeks !</ p >
</ body >
</ html >


输出: 在将鼠标指针移到段落上之前- 图片[1]-jQuery | hover()及其示例-yiteyi-C++库 将鼠标指针移到段落上方后- 图片[2]-jQuery | hover()及其示例-yiteyi-C++库 鼠标指针从段落移出后- 图片[3]-jQuery | hover()及其示例-yiteyi-C++库

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享