【问题标题】:jQuery: select all DIV's nested under specific DIVjQuery:选择嵌套在特定 DIV 下的所有 DIV
【发布时间】:2010-04-14 08:20:54
【问题描述】:

我有一个类似这样的架构:

<div id="container">
<div>stuff here</div>
<div>stuff here</div>
<div>stuff here</div>
<div>stuff here</div>
</div>

我想使用 jQuery 在鼠标进入#container 时隐藏光标。然而,当嵌套的 div 出现在顶部时,它并不能完全按照这种方式工作。将鼠标悬停在#container 中的任何 div 上时,如何隐藏鼠标光标。下面是光标隐藏代码。

        $('#container').mouseover(function()
        {
            $(this).css({cursor: 'none'});
        });

【问题讨论】:

  • 将 css 光标设置为“无”在 Chrome 中不起作用,仅供参考。
  • @jAndy 你如何在 Chrome 中解决这个问题?
  • 你为什么不使用纯 CSS 呢?我相信你可以使用 :hover 伪类实现相同的效果(IE 6 除外)
  • 我实际上刚刚完成了这个 chiborg。除了在 Chrome 下,它可以完美运行 :(
  • 很抱歉我没有Chrome的解决方案,只是注意到根据您的代码执行一些示例时的效果。

标签: jquery css-selectors cursor mouseover


【解决方案1】:

我敢说,你可以同时定位父 div 和子 div?

$('#container, #container div').mouseover(function()
{
    $(this).css({cursor: 'none'});
});

当然,我没有对此进行测试,但必须使用类似的方法将 &lt;li&gt; 的光标更改为 &lt;label&gt; 子级。

您可以使用 children() 函数稍微扩展它。

【讨论】:

    【解决方案2】:

    虽然有几个正确答案,但我认为这样更有效率。

    $('#container').mouseover(function(){
       $(this).children().andSelf().css('cursor', 'none');
    });
    

    这样你只使用一个事件监听器,在#container

    【讨论】:

      【解决方案3】:

      试试这个:

      $('#container > div').mouseover(function()
      {
          $(this).css('cursor', 'none');
      });
      

      【讨论】:

        【解决方案4】:

        使用 children() 选择器。

        $('#container').children().mouseover(function()
            {
                $(this).css({cursor: 'none'});
            });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-10-30
          • 2022-01-22
          • 2011-08-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多