Javascript 如何在Jquery中选择此选项

Javascript 如何在Jquery中选择此选项,javascript,jquery,Javascript,Jquery,我有这样的链接: <div id="section-1"> <a class="a" href="#">somethig text</a> <a class="a" href="#">somethig text</a> <a class="a" href="#">somethig text</a> <a class="a" href="#">somethig text</a>

我有这样的链接:

<div id="section-1">
  <a class="a" href="#">somethig text</a>
  <a class="a" href="#">somethig text</a>
  <a class="a" href="#">somethig text</a>
  <a class="a" href="#">somethig text</a>
  <a class="a" href="#">somethig text</a>
</div>
我想在鼠标悬停时为类a设置动画,但它会为所有名为a的类设置动画,我想为鼠标悬停的a设置动画使用:

$('.a').mouseover(function () {
    $(this).animate({ height: "100px" }, 150);
});
$(".a").mouseout(function () {
    $(this).animate({ height: "30px" }, 150);
});
使用:


您必须使用
,以获取当前悬停的元素

试试看

或者首选的方法是使用
.hover()


您必须使用
,以获取当前悬停的元素

试试看

或者首选的方法是使用
.hover()

通过使用
$('.a')选择a类的每个对象

$('.a').mouseover(function(){
 //here this will refer to current a tag
 $(this).animate({height:"100px"},150);
});

  $(".a").mouseout(function(){
 //here this will refer to current a tag
   $(this).animate({height:"30px"},150);
 });
通过使用
$('.a')选择a类的每个对象

$('.a').mouseover(function(){
 //here this will refer to current a tag
 $(this).animate({height:"100px"},150);
});

  $(".a").mouseout(function(){
 //here this will refer to current a tag
   $(this).animate({height:"30px"},150);
 });
animate()
之前使用
stop()
,因为它会停止当前正在运行的 匹配元素上的动画

animate()
之前使用
stop()
,因为它会停止当前正在运行的 匹配元素上的动画


:“除了事件对象外,事件处理函数还可以通过关键字
this
访问处理程序绑定到的DOM元素。要将DOM元素转换为可以使用jQuery方法的jQuery对象,只需执行
$(this)
”:“除了事件对象之外,事件处理函数还可以通过关键字
this
访问处理程序绑定到的DOM元素。要将DOM元素转换为可以使用jQuery方法的jQuery对象,只需执行
$(this)
"一个额外的
mouseout
处理程序将附加到
。每次触发
mouseover
事件时,都会附加一个
处理程序。oh没有注意到正在关闭的面包在外面。一个额外的
mouseout
处理程序将附加到
。每次触发
mouseover
事件时,都会附加一个
处理程序。oh没有注意到正在关闭的面包请解释您的答案,以便此问题的未来访问者了解您创建的解决方案。请解释您的答案,以便此问题的未来访问者了解您创建的解决方案。
$('.a').hover(function(){
   $(this).animate({height:"100"},150);
},function(){
   $(this).animate({height:"30"},150);
});
$('.a').mouseover(function(){
 //here this will refer to current a tag
 $(this).animate({height:"100px"},150);
});

  $(".a").mouseout(function(){
 //here this will refer to current a tag
   $(this).animate({height:"30px"},150);
 });
 $( ".a" ).hover(function() {
         $(this).stop().animate({height:"100px"},150);
     }, function() {
         $(this).stop().animate({height:"30px"},150);
     });
$( ".a" ).mouseover(function() {
         $(this).stop().animate({height:"100px"},150);
     }, function() {
         $(this).stop().animate({height:"30px"},150);
     });