Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery事件侦听器不工作 标签 $(文档).ready(函数(){ $('.button').mouseenter(函数(){ $(this.css('cursor','pointer'); $(this.addClass('green'); }); $('.button').mouseleave(函数(){ $(this.css('cursor','auto'); $(this.removeClass('green'); }); });_Javascript_Jquery_Css - Fatal编程技术网

Javascript jQuery事件侦听器不工作 标签 $(文档).ready(函数(){ $('.button').mouseenter(函数(){ $(this.css('cursor','pointer'); $(this.addClass('green'); }); $('.button').mouseleave(函数(){ $(this.css('cursor','auto'); $(this.removeClass('green'); }); });

Javascript jQuery事件侦听器不工作 标签 $(文档).ready(函数(){ $('.button').mouseenter(函数(){ $(this.css('cursor','pointer'); $(this.addClass('green'); }); $('.button').mouseleave(函数(){ $(this.css('cursor','auto'); $(this.removeClass('green'); }); });,javascript,jquery,css,Javascript,Jquery,Css,当我按下按钮时,什么也不会发生。为什么?我做错了什么?您的代码完全正确: 这是你的电话号码 我刚才又加了一句 <div id="mybutton" class="button">label</div> <script> $(document).ready(function () { $('.button').mouseenter(function () { $(this).css('cursor', '

当我按下按钮时,什么也不会发生。为什么?我做错了什么?

您的代码完全正确:

这是你的电话号码

我刚才又加了一句

<div id="mybutton" class="button">label</div>

<script>

      $(document).ready(function () {

        $('.button').mouseenter(function () {
            $(this).css('cursor', 'pointer');
            $(this).addClass('green');
        });

        $('.button').mouseleave(function () {
            $(this).css('cursor', 'auto');
            $(this).removeClass('green');
        });
      });
</script>

在jquery脚本文件链接之后将脚本块移到头部。

代码中没有任何错误。您是否包括Jquery库?仅供参考。您在这里所做的工作可以单独使用CSS完成
.green{
    color:green;
}