简体   繁体   English

在jquery中查找TR内的td的所有输入

[英]Find all input of td inside a TR in jquery

How we can find all the inputs of a td inside a tr in jquery. 我们如何在jquery中找到tr中的td的所有输入。 I have tr that will have multiple td in that td i have inputs and select so i want to get the values of the input types Code : 我有tr将有多个td在那个td我有输入和选择所以我想得到输入类型的值代码:

$('div#divid tbody.tbodyClass tr.trClass').each(function() {
            $(this td).find("input:text,select").each(function() {
                textVal = this.value;
                inputName = $(this).attr("name");
                formData+='&'+inputName+'='+textVal;
            });
            InsideCount++   
        });

I am trying to use this td's with each but i am not able to get the values and name of the inputs. 我试图使用这个td与每个,但我无法获得输入的值和名称。

You have syntax error at $(this td) . 您在$(this td)处有语法错误。 td should be used in find selector: td应该在find选择器中使用:

$(this).find("td input:text,td select").each(function() {
            textVal = this.value;
            inputName = $(this).attr("name");
            formData+='&'+inputName+'='+textVal;
        });
        InsideCount++  

as td s will be the only direct child of tr s , you can narrow down the selector to: 因为td s将是tr的唯一直接子tr ,你可以将选择器缩小到:

 $(this).find("input:text,select").each(function() {
  check updated code. move td inside find() selector.  

    $('div#divid tbody.tbodyClass tr.trClass').each(function() {
        $(this).find("td input:text,select").each(function() {
            textVal = this.value;
            inputName = $(this).attr("name");
            formData+='&'+inputName+'='+textVal;
        });
        InsideCount++   
    });

try this 尝试这个

$('tr:has(input)').each(function() {
var inputName = "";
var values = "";
$('input', this).each(function() {
inputName = inputName +","+ $(this).attr("name");
  values =  values + "," + $(this).val() 
});
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM