【问题标题】:making url hover when over td the url is in ::jquery::当 td 上的 url 在 ::jquery:: 中时使 url 悬停
【发布时间】:2011-01-18 06:05:04
【问题描述】:

在 jquery 中将鼠标悬停在 td 上时,如何使 td 中的 URL 触发“a:hover”css 效果

【问题讨论】:

    标签: jquery hover html-table


    【解决方案1】:

    你可以试试:

    $('td').hover(function() {
        $(this).find('a').mouseover();
    }, function() {
        $(this).find('a').mouseout();
    });
    

    【讨论】:

    • 我希望它是那么简单,这似乎是行不通的,因为我是通过 ajax 加载表格,所以即使添加实时它也无济于事......
       $('td').live('hover',function() { $(this).find('a.desc').mouseover(); }, function() { $(this).find('a .desc').mouseout(); }); 
    • @jason - 理想情况下,您应该首先包含类似的信息。
    【解决方案2】:

    我希望它这么简单,似乎那行不通,因为我正在通过 ajax 加载表格,所以即使添加 live 也无济于事......

    $('td').live('hover',function() { $(this).find('a.desc').mouseover(); }, 功能() { $(this).find('a.desc').mouseout(); });

    【讨论】:

    • 将此添加到原始问题并将其作为答案删除
    【解决方案3】:
    $('td').hover(function() {
        $(this).find('a').addClass('name-class-simulates-hover');
    }, function() {
        $(this).find('a').removeClass('name-class-simulates-hover');
    });
    

    也许添加一个与你的 a:hover 效果相同的类?

    【讨论】:

      【解决方案4】:

      某些事件无法通过 .live 或其他方式处理,因此,如果您发现自己需要将事件添加到新内容中,在通过 ajax 添加到页面之后或实际上作为添加到页面的一部分,您可以通过以下方式添加事件管理调用函数。

      function AddHover()
      {
        $('td').hover(function() { 
            $(this).find('a').addClass('myHoverClass');
        }, function() { 
            $(this).find('a').removeClass('myHoverClass'); 
        }); 
      };
      

      并在 ajax 加载中:

      剪辑...

      success: function(msg)
      {
          LoadTableData(msg);// this function would process and add your page elements
          AddHover();// this then adds the events to the new markup
      },
      

      ...结束片段 - 有关“成功:”的更多详细信息,请参阅 jQuery .ajax:

      【讨论】:

        【解决方案5】:

        感谢您的意见,Thomas 和 Mark。

        Thomas:我尝试了你的方法,但没有奏效,但它给了我一个想法,可以稍微调整一下,我得到了它的工作......

        $('tr').live('mouseenter',function() {
        $(this).find('a.desc').addClass('bold');
        

        }).live('mouseleave',function(){ $(this).find('a.desc').removeClass('bold'); });

        上面的代码是我当前的解决方案,它的工作,悬停似乎不起作用,因为再次需要 live 来删除“bold”类,因此我使用 mouseenter 和 mouseleave。

        在 $(this).find('a.desc').mouseover(); 上使用鼠标悬停这是不可能的...它甚至让谷歌浏览器滞后与众不同...所以我确信这不是一个好主意...

        Mark:这是一个非常有趣的想法,我会试一试,我尽量避免使用“.live()”,这似乎不是一个有效的方法,但是对于 web 2.0 来说这很难,

        【讨论】:

        • grr '在此处输入代码'是怎么回事它似乎不起作用...使用
           突出显示代码吗?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-27
        相关资源
        最近更新 更多