开发者社区> 问答> 正文

jQuery的功能为什么用不了

 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试</title>
    <script src="js/jquery-1.12.2.min.js"></script>
    <script>
        $("li").hover(
            function () {
                $(this).addClass("hover");
            },
            function () {
                $(this).removeClass("hover");
            }
        );
    </script>
    <style>
        #list li{
            list-style : none;
            width: 40px;
            height: 40px;
            background: navajowhite;
            float: left;
            margin-right: 10px;
        }
        #list li.hover{
            background: deepskyblue;
        }
    </style>
</head>
<body>
 <ul id="list">
     <li class="hover"></li>
     <li></li>
     <li></li>
     <li></li>
     <li></li>
     <li></li>

 </ul>
</body>
</html>

screenshottml

展开
收起
小旋风柴进 2016-03-16 16:59:24 2029 0
1 条回答
写回答
取消 提交回答
  • 放dom readny中绑定事件,要不找不到对象

     $(function(){
      $("li").hover(
                function () {
                    $(this).addClass("hover");
                },
                function () {
                    $(this).removeClass("hover");
                }
            );
    
    })
    2019-07-17 19:04:07
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
23-Vue.js在前端...1506518547.pdf 立即下载
现代Javascript高级教程 立即下载
JavaScript函数 立即下载