代码之家  ›  专栏  ›  技术社区  ›  Pierre de LESPINAY

jquery:排除包含的元素

  •  0
  • Pierre de LESPINAY  · 技术社区  · 15 年前
    舒埃特

    我想用鼠标来验证DIV而不是IMG

    $('div').mouseover(go_truc);
    

    我该怎么做?

    2 回复  |  直到 10 年前
        1
  •  0
  •   SLaks    15 年前

    处理 mouseenter 事件,但什么都不做 if ($(e.target).is('img')) .

    然后,处理 <img> 元素的 鼠标器 事件,并撤消效果。

        2
  •  0
  •   Pierre de LESPINAY    15 年前

    function do_trucs() {
      ...
    }
    
    function do_machins() {
      ...
      return (false);
    }
    
    $('div').mouseover(do_trucs);
    $('div img').mouseover(do_machins);
    

    这是可行的,但它是最简单/最好的解决方案吗?

    (不管怎样,我需要处理img.mouseover用于其他目的)