javascript jquery 获取 <td> 中的下一个输入元素值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19092123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 14:18:38  来源:igfitidea点击:

jquery get next input element value in <td>

javascriptjqueryhtmldom

提问by Ela Buwa

I have some piece of an html table which reads like

我有一些 html 表格,它读起来像

<table>
    <tr>
        <td>
            <input type="text" class="myclass" name="first_ele[]" value="100" />
        </td>
        <td>
            <input type="text" class="anotherclass" name="secon_ele[]" value="" />
        </td>
    </tr>
</table>

I have a piece of jquery that will get the value of the element that contains class "myclass" on keyup and I am getting the proper value. I need to get the value of the next input element. FYI , The table gets rows added dynamically. My issue is I don't know how to point to the next available input element.

我有一段 jquery,它将在 keyup 上获取包含类“myclass”的元素的值,并且我得到了正确的值。我需要获取下一个输入元素的值。仅供参考,该表会动态添加行。我的问题是我不知道如何指向下一个可用的输入元素。

my jquery to get the element which has the class "myclass" is as follows.

我的jquery获取具有类“myclass”的元素如下。

$('.tInputd').keyup(function(){
    var disc = $(this).val();
});

your help is greatly appreciated.

非常感谢您的帮助。

回答by Anton

Try

尝试

$('.myclass').on('keyup', function () {
    var disc = $(this).closest('td').next().find('input').val();
});

or

或者

$('.myclass').on('keyup', function () {
    var disc = $('.anotherclass').val();
});