jquery-selectors - JQuery,如何将相同的鼠标悬停效果应用于具有相同类的多个 div?请帮助?

标签 jquery-selectors mouseover html rollovers

我是 jQuery 的新手,我遇到了一些翻转问题,我试图将相同的“翻转”效果应用于多个 div,它似乎有效,唯一的事情是当我翻转一个元素时我的 div 得到相同的效果,当我希望它们在鼠标悬停时一次应用一个效果,这是我的代码

  $('div.pitem').bind('mouseenter mouseleave', function() {
  $('div.p-tab').toggleClass('pheader-bar-selected');
  });
  $('div.pitem').bind('mouseenter mouseleave', function() {
  $('div.p-fline').toggleClass('pfooter-bar-selected');
  });

我确实意识到我在所有 div 上都有相同的类,但我希望找到一种方法来做到这一点,而不是给每个 div 一个唯一的类或 id,任何帮助都会非常感谢!

最佳答案

你可以看看 $(this)。

解释于:http://remysharp.com/2007/04/12/jquerys-this-demystified/

下面是我如何使用它来给你举个例子

// megalink hover
$("div.megalink").hover(function(){
    $(this).css('background','#e1eefd');
    $(this).css('border-bottom','1px solid #0470B8');
 }, function(){
    $(this).css('background','#ffffff');
    $(this).css('border-bottom','1px solid #EBE7DE');
});

关于jquery-selectors - JQuery,如何将相同的鼠标悬停效果应用于具有相同类的多个 div?请帮助?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3739249/

相关文章:

jQuery:悬停时显示和隐藏子div

html - 单独 html 的多个包含

jQuery 选择器 : only link with images inside them

jQuery .attr() 导致 Internet Explorer 崩溃

jquery - 如何选择除第一次出现的类之外的所有类

javascript - 扩展接触盒

html - 如何使文本与图像居中对齐

jquery - 我如何使用 jquery 获取除按钮和隐藏字段之外的所有输入?

javascript - 使用 jQuery 检查 mouseleave() 时光标位于哪个元素上?

javascript - 新手帮助 : mouseover on image sometimes returning wrong image from image map