Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何选择与行的输入标记内的文本匹配的行_Jquery - Fatal编程技术网

Jquery 如何选择与行的输入标记内的文本匹配的行

Jquery 如何选择与行的输入标记内的文本匹配的行,jquery,Jquery,我有一个动态添加行的表,表中有文本框。我想做的是在添加第二行之前,它应该检查前一个文本框中是否已经存在该值如果是在第二行的另一个文本框中向当前值添加值,否则添加新行 我试过的是 if (tdlength != 0) { $('tr.invoicerow').each(function () { var RowProductNames = $(this).find("input.invoiceproduct").val(); if (

我有一个动态添加行的表,表中有文本框。我想做的是在添加第二行之前,它应该检查前一个文本框中是否已经存在该值如果是在第二行的另一个文本框中向当前值添加值,否则添加新行

我试过的是

if (tdlength != 0) {
        $('tr.invoicerow').each(function () {
            var RowProductNames = $(this).find("input.invoiceproduct").val();
            if (RowProductNames == InvoiceProductName) {
                // Sum The Rate to Value alredy exists In text box
            } else {
                row = "<tr class='invoicerow'><td hidden><input class='dcid' value=" + deliverychallanid + "></td><td><input class='case invoicechkbox' type='checkbox'></td><td><input class='form-control invoiceproduct' id='invoiceproduct_" + rowno + "' value=" + InvoiceProductName + "></td><td><input class='form-control invoiceunit' id='invoiceunit_" + rowno + "' value=" + InvoiceUnit + "></td><td><input class='form-control invoicerate' id='invoicerate_" + rowno + "' value=" + InvoiceRatePerUnit + "></td><td><input class='form-control invoicenos' id='invoicenos_" + rowno + "'value=" + 0 + "></td><td><input class='form-control invoicequantity' id='invoicequantity_" + rowno + "' value=" + 0 + "></td><td><input class='form-control invoicecapacity' id='invoicecapacity_" + rowno + "'value=" + value.Capacity + "></td><td><input class='form-control invoiceamount' id='invoiceamount_" + rowno + "' value=" + Totalamount + "></td></tr>";
                $('#invoicebody').append(row);
            }
        });
        } else {
            row = "<tr class='invoicerow'><td hidden><input class='dcid' value=" + deliverychallanid + "></td><td><input class='case invoicechkbox' type='checkbox'></td><td><input class='form-control invoiceproduct' id='invoiceproduct_" + rowno + "' value=" + InvoiceProductName + "></td><td><input class='form-control invoiceunit' id='invoiceunit_" + rowno + "' value=" + InvoiceUnit + "></td><td><input class='form-control invoicerate' id='invoicerate_" + rowno + "' value=" + InvoiceRatePerUnit + "></td><td><input class='form-control invoicenos' id='invoicenos_" + rowno + "'value=" + 0 + "></td><td><input class='form-control invoicequantity' id='invoicequantity_" + rowno + "' value=" + 0 + "></td><td><input class='form-control invoicecapacity' id='invoicecapacity_" + rowno + "'value=" + value.Capacity + "></td><td><input class='form-control invoiceamount' id='invoiceamount_" + rowno + "' value=" + Totalamount + "></td></tr>";
            $('#invoicebody').append(row);

    }
当我尝试这段代码时,发生的是 首先,它检查第一行中的文本是否与另一个文本框中的更改相匹配 它再次检查第二行文本是否不匹配,它添加新行并继续添加,直到循环完成。。如何解决这个问题


谢谢

请参阅。我想这就是你想要的:

    var test = false;
    $('tr.invoicerow').each(function () {           
        var RowProductNames = $(this).find("input.invoiceproduct").val();
        if (RowProductNames == InvoiceProductName) {

            // Sum The Rate to Value alredy exists In text box
            test = true;
            return false;
        } 
    });
    if(!test){
        row = "<tr class='invoicerow'><td hidden><input class='dcid' value=" + deliverychallanid + "></td><td><input class='case invoicechkbox' type='checkbox'></td><td><input class='form-control invoiceproduct' id='invoiceproduct_" + rowno + "' value=" + InvoiceProductName + "></td><td><input class='form-control invoiceunit' id='invoiceunit_" + rowno + "' value=" + InvoiceUnit + "></td><td><input class='form-control invoicerate' id='invoicerate_" + rowno + "' value=" + InvoiceRatePerUnit + "></td><td><input class='form-control invoicenos' id='invoicenos_" + rowno + "'value=" + 0 + "></td><td><input class='form-control invoicequantity' id='invoicequantity_" + rowno + "' value=" + 0 + "></td><td><input class='form-control invoicecapacity' id='invoicecapacity_" + rowno + "'value=" + value.Capacity + "></td><td><input class='form-control invoiceamount' id='invoiceamount_" + rowno + "' value=" + Totalamount + "></td></tr>"
        $('#invoicebody').append(row);
    }

你的代码应该是这样的

$('tr.invoicerow').each(function () {

                    var RowProductNames = $(this).find("input.invoiceproduct").val();
                    if (RowProductNames == InvoiceProductName) {

                     var c=parseInt($(this).find("td input.invoicerate").val())+parseInt(USER_INPUTTED_VALUE);
                     $(this).find("td input.invoicerate").val(c);
                    } else {
                        row = "<tr class='invoicerow'><td hidden><input class='dcid' value=" + deliverychallanid + "></td><td><input class='case invoicechkbox' type='checkbox'></td><td><input class='form-control invoiceproduct' id='invoiceproduct_" + rowno + "' value=" + InvoiceProductName + "></td><td><input class='form-control invoiceunit' id='invoiceunit_" + rowno + "' value=" + InvoiceUnit + "></td><td><input class='form-control invoicerate' id='invoicerate_" + rowno + "' value=" + InvoiceRatePerUnit + "></td><td><input class='form-control invoicenos' id='invoicenos_" + rowno + "'value=" + 0 + "></td><td><input class='form-control invoicequantity' id='invoicequantity_" + rowno + "' value=" + 0 + "></td><td><input class='form-control invoicecapacity' id='invoicecapacity_" + rowno + "'value=" + value.Capacity + "></td><td><input class='form-control invoiceamount' id='invoiceamount_" + rowno + "' value=" + Totalamount + "></td></tr>"
                        $('#invoicebody').append(row);
                    }

                });
            }
几件事:我假设要设置的textbox类是invoicerate。还假设用户正在表单的其他部分输入数据。
如果没有,请澄清。

您所说的“如果是,将值添加到当前值”是什么意思?当我添加第一行时,请让我解释清楚,如果第一行中有两个字段,则第一行文本为foo,第二行文本值为2。当我尝试添加第二行时,如果第二行文本也为foo,则会有一些值将newrate添加到第一行的值