【问题标题】:jQuery: mouseover function not triggering for unordered list descendantjQuery:鼠标悬停功能不会触发无序列表后代
【发布时间】:2013-04-18 07:31:56
【问题描述】:

我有一个如下的无序列表:

<ul id="dasList">
 <li id="dasListItem1">
  <span>
   <div style="height:10px">
     <label id="dasLabel1">LaLaLa</label>
   </div>
   <a id="dasAnchor1"></a>
  </span>
 </li>
 <li id="dasListItem2">
  <span>
   <div style="height:10px">
     <label id="dasLabel2">LaLaLa</label>
   </div>
   <a id="dasAnchor2"></a>
  </span>
 </li>
</ul>

现在这就是我想要做的。我想在列表项中包含的锚标记上触发鼠标悬停功能。目前,我正在使用这个:

$("#dasList a").mouseover(function(){
        alert('i find your lack of faith disturbing');
    });

但由于某种不敬虔的原因,它没有触发。我也设置了断点,但无济于事:(

有没有更好的方法来做到这一点?

【问题讨论】:

    标签: jquery html html-lists anchor mouseover


    【解决方案1】:

    我想通了!这是我的浏览器的问题 :) 显然,当 chrome 开发工具打开时,最新的 Chrome 更新似乎将鼠标悬停识别为 mouseclick:/

    老实说,这是一个非常奇怪的场景,也是我从未预料到的。终于要结束这个问题了,我想是时候结束了!

    【讨论】:

      【解决方案2】:

      应该是

       $("#dasList li a").mouseover(function(){
         ...
      

      使用 find()

       $("#dasLis").find("a").mouseover(function(){
      

      使用带有^的属性选择器,它选择所有以提供的字符串开头的元素

       $("a[id^='dasAnchor']").mouseover(function(){
      

      【讨论】:

      • 该功能似乎仅在单击列表项时触发。
      • 我知道:/ 好吧,我不能发布确切的代码。问题中的代码是它的精简版..
      猜你喜欢
      • 1970-01-01
      • 2011-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-23
      • 2018-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多