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

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

Find all input of td inside a TR in jquery

javascriptjquery

提问by Developer

How we can find all the inputs of a td inside a tr in jquery. 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 :

我们如何在 jquery 的 tr 中找到 td 的所有输入。我有 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 与每个一起使用,但我无法获取输入的值和名称。

回答by Milind Anantwar

You have syntax error at $(this td). td should be used in find selector:

您在 处有语法错误$(this td)。td 应该用于查找选择器:

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

as tds will be the only direct child of trs , you can narrow down the selector to:

由于tds 将是 s 的唯一直接子代tr,您可以将选择器缩小为:

 $(this).find("input:text,select").each(function() {

回答by Nishit Maheta

  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++   
    });

回答by tech-gayan

try this

尝试这个

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