【问题标题】:What's Zepto.js alternative to jQuery's $(this).parent().parent().find('.active')?jQuery 的 $(this).parent().parent().find('.active') 的 Zepto.js 替代品是什么?
【发布时间】:2011-05-22 05:25:23
【问题描述】:

什么是 Zepto.js 替代 jQuery$(this).parent().parent().find('.active')

【问题讨论】:

    标签: javascript zepto


    【解决方案1】:

    这个问题大约有 4 个月的历史,Zepto 框架会定期更新。

    $(this).parent().parent().find('.active') 现在可以使用了。

    根据 git repo 源代码树,此支持由 Mislav Marohnić 于 2010 年 12 月 20 日添加(提交哈希 784de340)。

    【讨论】:

      【解决方案2】:

      我在API 中没有看到.parent() 方法,因此您可能只需要这样做(未经测试!):

      $($(this).get(0).parentNode.parentNode).find('.active').hide();
      

      【讨论】:

        【解决方案3】:

        zepto 有类似 Element#upfrom 原型的东西来搜索祖先。它被称为closest。您需要有一个班级或知道谁是家长。

        $(this).closest("div.parentclass").find('.active')
        

        【讨论】:

        • 谢谢。我怀疑它是否比 karim79 的解决方案更快。
        【解决方案4】:

        Zepto 已经实现了 .parent() 方法。见http://zeptojs.com/#parent

        【讨论】:

          猜你喜欢
          • 2011-09-03
          • 2014-09-09
          • 2014-07-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-04
          相关资源
          最近更新 更多