【问题标题】:Cannot select input jquery无法选择输入 jquery
【发布时间】:2015-08-16 09:20:24
【问题描述】:

这是一个非常简单的问题,但我不知道如何从。

<div>
    <input>
</div>
<p id="pepe"></p>

以下内容:

$("#pepe").prev()

给我 div,我如何获得第一个孩子(输入)

【问题讨论】:

    标签: jquery


    【解决方案1】:

    正如您所见,prev() 获取前一个兄弟元素。要从那里获取input,您需要使用find(),以及:first,假设您的实际工作HTML 中有多个:

    $("#pepe").prev().find('input:first');
    

    【讨论】:

    【解决方案2】:

    在您的代码.prev() 中指出 div 元素而不是输入。如果你有搜索输入意味着在 jquery 中使用.find()

    $("#pepe").prev().find('input')
    

    【讨论】:

      【解决方案3】:

      $("#pepe").prev() 为您提供&lt;div&gt;

      试试$("#pepe").prev().children('input');

      【讨论】:

        猜你喜欢
        • 2011-09-19
        • 1970-01-01
        • 2012-01-21
        • 2023-01-13
        • 2013-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-08
        相关资源
        最近更新 更多