javascript Jquery选择TD内的输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10624417/
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-26 10:29:38  来源:igfitidea点击:

Jquery select input that is within a TD

javascriptjqueryhtmljquery-selectors

提问by carlg

Here is the HTML code that I copied/pasted using Firebug:

这是我使用 Firebug 复制/粘贴的 HTML 代码:

<div id="TBI">
<tr class="t-state-selected t-grid-edit-row">
    <td>8081</td>

    <td class="t-grid-edit-cell">
        <input id="ijn" class="text-box single-line valid" type="text" value=""  name="ijn"> 
    </td>

I'm able to access the 2nd cell of this table using the following:

我可以使用以下方法访问该表的第二个单元格:

$('#TBI tr.t-state-selected')[0].cells[1] 

and all works well.

一切正常。

But, how can I get a jquery reference to the input that is contained within the TD? Once I figure out how to get a selector for that text box, I can manipulate it as I wish.

但是,如何获得对包含在 TD 中的输入的 jquery 引用?一旦我弄清楚如何为该文本框获取选择器,我就可以随心所欲地操作它。

Thanks ahead of time for help!

提前感谢您的帮助!

回答by mattytommo

Just try:

你试一试:

$("#TBI tr.t-state-selected input")

Or for the input inside the second td:

或者对于第二个 td 内的输入:

$("#TBI tr.t-state-selected:nth-child(1) input");

Demo: Fiddle

演示:小提琴

回答by jmar777

$('#TBI tr.t-state-selected td input')

回答by The System Restart

$("input[type=text]", "div#TBI tr.t-state-selected td");