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() ;

但两者都不起作用.

An example of the 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');

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

Jquery相关问答推荐

通过 Ajax POST 将按钮值从 HTML 发送到 Flask 时出现空数据

:eq Jquery,我似乎无法显示第一个之后的元素

使用jquery将外部代码插入div

在 JSON 对象上使用 jQuery 的 find()

在 for 循环中分配点击处理程序

以ajax方式在rails 3中提交表单(使用jQuery)

jQuery UI 自动完成宽度未正确设置

jQuery获取表单字段值

页面滚动后,jQuery可拖动在错误的位置显示助手

jQuery getJSON 将结果保存到变量中

jQuery 插件:添加回调功能

如何检测是否安装了 Flash,如果没有,显示一个隐藏的 div 通知用户?

隐藏 div 但保留空白

使用 jQuery 将事件侦听器添加到动态添加的元素

如何复制 pinterest.com 的绝对 div 堆叠布局

如何在没有鼠标事件的情况下在 jQuery 中获取鼠标位置?

Chrome 中的 AJAX 发送选项而不是 GET/POST/PUT/DELETE?

我应该在addClass之前使用hasClass吗?

AJAX 成功中的 $(this) 不起作用

catch forEach 最后一次迭代