2014-02-08 179 views
-1
<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> 

当我mouseenter #mybutton没有任何反应。为什么?我究竟做错了什么?jQuery事件监听器不工作

+1

你的代码没有错。你包括Jquery库吗? –

+0

适用于我http://jsfiddle.net/fg7ys/ –

+1

仅供参考您在这里可以使用CSS完成的工作 – George

回答

0

移动你的脚本块入脑后jQuery脚本文件的链接。

0

你的代码是完全没有问题:

这里是jsfiddle

我刚加入

.green{ 
    color:green; 
}