jQuery查找最接近的匹配元素 [英] Jquery find nearest matching element

查看:258
本文介绍了jQuery查找最接近的匹配元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列带有列的行,并且我想选择在input字段(价格输入)的前一列中的input字段的值,该键在按键时调用函数被释放.

I have a series of rows with columns and I want to select the value of an input field that is in a previous column to the input field (price input) that I am calling a function on when a key is released.

我尝试过:

quantity = $(this).parent().parent().children().val() ;
quantity = $(this).parent().parent().children().closest('.inputQty', this).val() ;

但都不行.

DOM的示例:

<div class="row">
    <div class="column"><input class="inputQty" id="quantity0" /></div>
    <div class="column"><input class="someOther" id="Other0" /></div>
    <div class="column">
        <div class="cSelect">
            <select id="currency0"><option>£</option></select>
            <input class="price" id="price0" />
        </div>
    </div>
</div>

推荐答案

var otherInput = $(this).closest('.row').find('.inputQty');

上升到一行,然后下降到.inputQty.

That goes up to a row level, then back down to .inputQty.

这篇关于jQuery查找最接近的匹配元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆