在JavaScript中,hover()方法用于规定当鼠标指针悬停在被选元素上时要运行的函数,既可以设置指针在元素上时的函数,也可以设置指针离开时的函数,语法为“$(元素).hover(inFunction,outFunction)”。

本教程操作环境:windows10系统、javascript1.8.5版、Dell G3电脑。
javascript中hover的用法是什么
hover() 方法规定当鼠标指针悬停在被选元素上时要运行的两个函数。
方法触发 mouseenter 和 mouseleave 事件。
立即学习“Java免费学习笔记(深入)”;
注意: 如果只指定一个函数,则 mouseenter 和 mouseleave 都执行它。
语法为:
$(selector).hover(inFunction,outFunction)
调用:
$( selector ).hover( handlerIn, handlerOut )
等同以下方式:
$( selector ).mouseenter( handlerIn ).mouseleave( handlerOut );
注意:如果只规定了一个函数,则它将会在 mouseenter 和 mouseleave 事件上运行。
调用:
$(selector).hover(handlerInOut)
等同于:
$( selector ).on( "mouseenter mouseleave", handlerInOut );
示例如下:
<html>
<head>
<meta charset="utf-8">
<title>123</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.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>输出结果:

【相关推荐:javascript学习教程】
以上就是javascript中hover的用法是什么的详细内容,更多请关注php中文网其它相关文章!
 
                        
                        java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
 
                 
                                
                                 收藏
收藏
                                                                             
                                
                                 收藏
收藏
                                                                             
                                
                                 收藏
收藏
                                                                            Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号