У меня есть таблица, и я добавляю строку, клонируя ее. У меня есть поле в виде раскрывающегося меню, и когда значение раскрывающегося списка изменяется, включается соответствующее отключенное поле. Проблема, которую я получаю, заключается в том, что если я изменю значения моего раскрывающегося списка в предыдущей строке, столбцы текущего Строка также включена. Любая помощь будет оценена. Благодарю.

function disableField() { var Count = $('#dataTable tr').length; if (Count == 2){ $("input").not('.DeleteButton').prop('disabled', false); }else{ $("input").prop('disabled', false); } } var regex = /^([a-zA-Z0-9 _-] )$/; var cindex = 0; var quicklink = '' ; $(document).on('click','.Buttons', function(addrow) { var count = $('table tr:last input:text').filter((_,el) ={amp}gt; el.value.trim() == "").length; if(count || !$('.id_100 option[value=code]').attr('selected','selected')){ alert("Please fill the current row"); return false; } var $tr = $('#dataTable tbody tr:last'); var $clone = $tr.clone(true); cindex  ; $clone.find(':input').not('select').not('.DeleteButton').val('').attr('disabled', true); $clone.attr('id', 'id' (cindex) ); //update row id if required //update ids of elements in row $clone.find("*").each(function() { var id = this.id || ""; if(id != ""){ var match = id.match(regex) || []; if (match.length == 2) { this.id = this.name   (cindex); } } }); $tr.after($clone); }); 
 {amp}lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"{amp}gt;{amp}lt;/script{amp}gt; {amp}lt;table cellspacing="0" cellpadding="0" border="0" id="mainbox" class="mainbox"{amp}gt;{amp}lt;tr{amp}gt;{amp}lt;td{amp}gt; {amp}lt;div class="toppanel"{amp}gt;{amp}lt;ul{amp}gt;{amp}lt;li{amp}gt;{amp}lt;/li{amp}gt;{amp}lt;/ul{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;div class="abcd"{amp}gt; {amp}lt;!--mainbox middlepanel start--{amp}gt; {amp}lt;table cellspacing="0" cellpadding="0" border="0" id="maintable" class="maintable"{amp}gt; {amp}lt;tr{amp}gt; {amp}lt;td valign="top"{amp}gt; {amp}lt;div id="pageheadingpanel"{amp}gt; {amp}lt;div id="pageheading"{amp}gt;Quick Link Widget Configuration{amp}lt;/div{amp}gt; {amp}lt;div id="pageheadingdate"{amp}gt;{amp}lt;xsl:call-template name="formatted_date"/{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;tr{amp}gt; {amp}lt;td height="100%" valign="top"{amp}gt; {amp}lt;div class="y_scroll" id="contentarea"{amp}gt; {amp}lt;div class="contentarea"{amp}gt;{amp}lt;!--contentarea start--{amp}gt; {amp}lt;span id="box" class="box"{amp}gt; {amp}lt;!--rounded curve/border start--{amp}gt; {amp}lt;div class="middlepanel"{amp}gt; {amp}lt;!--contentarea box middlepanel start--{amp}gt; {amp}lt;div style="display:block" id="textBox1" {amp}gt; {amp}lt;span id="box1" class="box"{amp}gt; {amp}lt;div class="toppanel"{amp}gt;{amp}lt;ul{amp}gt;{amp}lt;li{amp}gt;{amp}lt;/li{amp}gt;{amp}lt;/ul{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;div class="middlepanel"{amp}gt; {amp}lt;table border="0" cellspacing="1" cellpadding="1" id="dataTable" name="dataTable" class="graphtable"{amp}gt; {amp}lt;thead{amp}gt; {amp}lt;tr{amp}gt; {amp}lt;td class="headingalign" width="16%"{amp}gt;Links{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="32%"{amp}gt;Desciption{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="16%"{amp}gt;Image{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="16%"{amp}gt;URL{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="05%"{amp}gt;{amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;/thead{amp}gt; {amp}lt;tbody{amp}gt; {amp}lt;tr id="id0" class="vals" name="id0"{amp}gt; {amp}lt;td{amp}gt; {amp}lt;div class="id_100"{amp}gt; {amp}lt;select type="select-one" id='fldsearch' class="objselect" name="fldsearch" onChange="disableField()" {amp}gt; {amp}lt;option value=""{amp}gt;Select{amp}lt;/option{amp}gt; {amp}lt;xsl:for-each select="values from local db"{amp}gt; {amp}lt;xsl:sort order="ascending" select="description"/{amp}gt; {amp}lt;option value="{description}"{amp}gt; {amp}lt;xsl:value-of select="description"/{amp}gt; {amp}lt;/option{amp}gt; {amp}lt;/xsl:for-each{amp}gt; {amp}lt;/select{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input id="flddesc" name="flddesc" maxlength="500" disabled="true" class="objinputtext1" size="85" value="{//RESPONSE}" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input id="fldimg" name="fldimg" maxlength="50" disabled="true" class="objinputtext2" size="35" value="{//RESPONSE}" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input id="fldurl" name="fldurl" maxlength="15" disabled="true" class="objinputtext3" size="35" value="{//RESPONSE}" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input tabindex="6" value="Delete Row" disabled="true" class="DeleteButton" type="button" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;/tbody{amp}gt; {amp}lt;/table{amp}gt; {amp}lt;div class="buttonarea"{amp}gt; {amp}lt;ul{amp}gt; {amp}lt;li{amp}gt;{amp}lt;input tabindex="6" id="Button3" value="Add New Row" class="Buttons" name="Button3" type="button" /{amp}gt;{amp}lt;/li{amp}gt; {amp}lt;/ul{amp}gt; {amp}lt;/div{amp}gt; 

Вы передаете текущий целевой элемент таблицы tr в функцию onchange

  function disableField(targetElement) { var Count = $('#dataTable tr').length; if (Count == 2){ $(targetElement).closest('tr').find('input').not('.DeleteButton').prop('disabled', false); }else{ $(targetElement).closest('tr').find('input').prop('disabled', false); } } var regex = /^([a-zA-Z0-9 _-] )$/; var cindex = 0; var quicklink = '' ; $(document).on('click','.Buttons', function(addrow) { var count = $('table tr:last input:text').filter((_,el) ={amp}gt; el.value.trim() == "").length; if(count || !$('.id_100 option[value=code]').attr('selected','selected')){ alert("Please fill the current row"); return false; } var $tr = $('#dataTable tbody tr:last'); var $clone = $tr.clone(true); cindex  ; $clone.find(':input').not('select').not('.DeleteButton').val('').attr('disabled', true); $clone.attr('id', 'id' (cindex) ); //update row id if required //update ids of elements in row $clone.find("*").each(function() { var id = this.id || ""; if(id != ""){ var match = id.match(regex) || []; if (match.length == 2) { this.id = this.name   (cindex); } } }); $tr.after($clone); }); 
 {amp}lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"{amp}gt;{amp}lt;/script{amp}gt; {amp}lt;table cellspacing="0" cellpadding="0" border="0" id="mainbox" class="mainbox"{amp}gt;{amp}lt;tr{amp}gt;{amp}lt;td{amp}gt; {amp}lt;div class="toppanel"{amp}gt;{amp}lt;ul{amp}gt;{amp}lt;li{amp}gt;{amp}lt;/li{amp}gt;{amp}lt;/ul{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;div class="abcd"{amp}gt; {amp}lt;!--mainbox middlepanel start--{amp}gt; {amp}lt;table cellspacing="0" cellpadding="0" border="0" id="maintable" class="maintable"{amp}gt; {amp}lt;tr{amp}gt; {amp}lt;td valign="top"{amp}gt; {amp}lt;div id="pageheadingpanel"{amp}gt; {amp}lt;div id="pageheading"{amp}gt;Quick Link Widget Configuration{amp}lt;/div{amp}gt; {amp}lt;div id="pageheadingdate"{amp}gt;{amp}lt;xsl:call-template name="formatted_date"/{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;tr{amp}gt; {amp}lt;td height="100%" valign="top"{amp}gt; {amp}lt;div class="y_scroll" id="contentarea"{amp}gt; {amp}lt;div class="contentarea"{amp}gt;{amp}lt;!--contentarea start--{amp}gt; {amp}lt;span id="box" class="box"{amp}gt; {amp}lt;!--rounded curve/border start--{amp}gt; {amp}lt;div class="middlepanel"{amp}gt; {amp}lt;!--contentarea box middlepanel start--{amp}gt; {amp}lt;div style="display:block" id="textBox1" {amp}gt; {amp}lt;span id="box1" class="box"{amp}gt; {amp}lt;div class="toppanel"{amp}gt;{amp}lt;ul{amp}gt;{amp}lt;li{amp}gt;{amp}lt;/li{amp}gt;{amp}lt;/ul{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;div class="middlepanel"{amp}gt; {amp}lt;table border="0" cellspacing="1" cellpadding="1" id="dataTable" name="dataTable" class="graphtable"{amp}gt; {amp}lt;thead{amp}gt; {amp}lt;tr{amp}gt; {amp}lt;td class="headingalign" width="16%"{amp}gt;Links{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="32%"{amp}gt;Desciption{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="16%"{amp}gt;Image{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="16%"{amp}gt;URL{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="05%"{amp}gt;{amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;/thead{amp}gt; {amp}lt;tbody{amp}gt; {amp}lt;tr id="id0" class="vals" name="id0"{amp}gt; {amp}lt;td{amp}gt; {amp}lt;div class="id_100"{amp}gt; {amp}lt;select type="select-one" id='fldsearch' class="objselect" name="fldsearch" onChange="disableField(this)" {amp}gt; {amp}lt;option value=""{amp}gt;Select{amp}lt;/option{amp}gt; {amp}lt;xsl:for-each select="values from local db"{amp}gt; {amp}lt;xsl:sort order="ascending" select="description"/{amp}gt; {amp}lt;option value="{description}"{amp}gt; {amp}lt;xsl:value-of select="description"/{amp}gt; {amp}lt;/option{amp}gt; {amp}lt;/xsl:for-each{amp}gt; {amp}lt;/select{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input id="flddesc" name="flddesc" maxlength="500" disabled="true" class="objinputtext1" size="85" value="{//RESPONSE}" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input id="fldimg" name="fldimg" maxlength="50" disabled="true" class="objinputtext2" size="35" value="{//RESPONSE}" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input id="fldurl" name="fldurl" maxlength="15" disabled="true" class="objinputtext3" size="35" value="{//RESPONSE}" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input tabindex="6" value="Delete Row" disabled="true" class="DeleteButton" type="button" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;/tbody{amp}gt; {amp}lt;/table{amp}gt; {amp}lt;div class="buttonarea"{amp}gt; {amp}lt;ul{amp}gt; {amp}lt;li{amp}gt;{amp}lt;input tabindex="6" id="Button3" value="Add New Row" class="Buttons" name="Button3" type="button" /{amp}gt;{amp}lt;/li{amp}gt; {amp}lt;/ul{amp}gt; {amp}lt;/div{amp}gt; 

Вам нужно передать this (текущий) элемент в функцию onChange.

 {amp}lt;select type="select-one" id='fldsearch' class="objselect" name="fldsearch" onChange="disableField(this)" {amp}gt; 

Теперь вы должны использовать this чтобы включить, отключить ваш элемент внутри tr .

  function disableField(ele) { var Count = $('#dataTable tr').length; if (Count == 2) { $(ele).closest('tr').find("input").not('.DeleteButton').prop('disabled', false); } else { $(ele).closest('tr').find("input").prop('disabled', false); } } 

Вы делаете пару вещей неправильно, вот видите разницу с вашим кодом. Вы не должны вызывать .not('.DeleteButton') при добавлении новой строки и Count == 2 вызывая проблему, смотрите, я исправил это.

 function disableField(e) { $(e).closest('tr').find("input").prop('disabled', false); } var regex = /^([a-zA-Z0-9 _-] )$/; var cindex = 0; var quicklink = '' ; $(document).on('click','.Buttons', function(addrow) { var count = $('table tr:last input:text').filter((_,el) ={amp}gt; el.value.trim() == "").length; if(count || !$('.id_100 option[value=code]').attr('selected','selected')){ alert("Please fill the current row"); return false; } var $tr = $('#dataTable tbody tr:last'); var $clone = $tr.clone(true); cindex  ; $clone.find('input:text').val('').attr('disabled', true); $clone.find('input:button').attr('disabled', true); $clone.attr('id', 'id' (cindex) ); //update row id if required //update ids of elements in row $clone.find("*").each(function() { var id = this.id || ""; if(id != ""){ var match = id.match(regex) || []; if (match.length == 2) { this.id = this.name   (cindex); } } }); $tr.after($clone); }); 
 {amp}lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"{amp}gt;{amp}lt;/script{amp}gt; {amp}lt;table cellspacing="0" cellpadding="0" border="0" id="mainbox" class="mainbox"{amp}gt;{amp}lt;tr{amp}gt;{amp}lt;td{amp}gt; {amp}lt;div class="toppanel"{amp}gt;{amp}lt;ul{amp}gt;{amp}lt;li{amp}gt;{amp}lt;/li{amp}gt;{amp}lt;/ul{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;div class="abcd"{amp}gt; {amp}lt;!--mainbox middlepanel start--{amp}gt; {amp}lt;table cellspacing="0" cellpadding="0" border="0" id="maintable" class="maintable"{amp}gt; {amp}lt;tr{amp}gt; {amp}lt;td valign="top"{amp}gt; {amp}lt;div id="pageheadingpanel"{amp}gt; {amp}lt;div id="pageheading"{amp}gt;Quick Link Widget Configuration{amp}lt;/div{amp}gt; {amp}lt;div id="pageheadingdate"{amp}gt;{amp}lt;xsl:call-template name="formatted_date"/{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;tr{amp}gt; {amp}lt;td height="100%" valign="top"{amp}gt; {amp}lt;div class="y_scroll" id="contentarea"{amp}gt; {amp}lt;div class="contentarea"{amp}gt;{amp}lt;!--contentarea start--{amp}gt; {amp}lt;span id="box" class="box"{amp}gt; {amp}lt;!--rounded curve/border start--{amp}gt; {amp}lt;div class="middlepanel"{amp}gt; {amp}lt;!--contentarea box middlepanel start--{amp}gt; {amp}lt;div style="display:block" id="textBox1" {amp}gt; {amp}lt;span id="box1" class="box"{amp}gt; {amp}lt;div class="toppanel"{amp}gt;{amp}lt;ul{amp}gt;{amp}lt;li{amp}gt;{amp}lt;/li{amp}gt;{amp}lt;/ul{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;div class="middlepanel"{amp}gt; {amp}lt;table border="0" cellspacing="1" cellpadding="1" id="dataTable" name="dataTable" class="graphtable"{amp}gt; {amp}lt;thead{amp}gt; {amp}lt;tr{amp}gt; {amp}lt;td class="headingalign" width="16%"{amp}gt;Links{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="32%"{amp}gt;Desciption{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="16%"{amp}gt;Image{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="16%"{amp}gt;URL{amp}lt;/td{amp}gt; {amp}lt;td class="headingalign" width="05%"{amp}gt;{amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;/thead{amp}gt; {amp}lt;tbody{amp}gt; {amp}lt;tr id="id0" class="vals" name="id0"{amp}gt; {amp}lt;td{amp}gt; {amp}lt;div class="id_100"{amp}gt; {amp}lt;select type="select-one" id='fldsearch' class="objselect" name="fldsearch" onChange="disableField(this)" {amp}gt; {amp}lt;option value=""{amp}gt;Select{amp}lt;/option{amp}gt; {amp}lt;xsl:for-each select="values from local db"{amp}gt; {amp}lt;xsl:sort order="ascending" select="description"/{amp}gt; {amp}lt;option value="{description}"{amp}gt; {amp}lt;xsl:value-of select="description"/{amp}gt; {amp}lt;/option{amp}gt; {amp}lt;/xsl:for-each{amp}gt; {amp}lt;/select{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input id="flddesc" name="flddesc" maxlength="500" disabled="true" class="objinputtext1" size="85" value="{//RESPONSE}" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input id="fldimg" name="fldimg" maxlength="50" disabled="true" class="objinputtext2" size="35" value="{//RESPONSE}" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input id="fldurl" name="fldurl" maxlength="15" disabled="true" class="objinputtext3" size="35" value="{//RESPONSE}" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;td{amp}gt; {amp}lt;input tabindex="6" value="Delete Row" disabled="true" class="DeleteButton" type="button" /{amp}gt; {amp}lt;/td{amp}gt; {amp}lt;/tr{amp}gt; {amp}lt;/tbody{amp}gt; {amp}lt;/table{amp}gt; {amp}lt;div class="buttonarea"{amp}gt; {amp}lt;ul{amp}gt; {amp}lt;li{amp}gt;{amp}lt;input tabindex="6" id="Button3" value="Add New Row" class="Buttons" name="Button3" type="button" /{amp}gt;{amp}lt;/li{amp}gt; {amp}lt;/ul{amp}gt; {amp}lt;/div{amp}gt; 

Как можно меньше.

 function add_row(){ var code = Math.floor((Math.random() * 99999999999999)   1) var row = '{amp}lt;tr id="row-' code '"'  '{amp}gt;'  '{amp}lt;td{amp}gt;'  '{amp}lt;select '  'onchange="disabledatr('  "'" code "'"   ')"'   '{amp}gt;'  '{amp}lt;option value="true"{amp}gt;disabled{amp}lt;/option{amp}gt;'  '{amp}lt;option value="false"{amp}gt;not disabled{amp}lt;/option{amp}gt;'  '{amp}lt;/select{amp}gt;'  '{amp}lt;/td{amp}gt;'  '{amp}lt;td{amp}gt;{amp}lt;input type="text" disabled="false"{amp}gt;{amp}lt;/td{amp}gt;'  '{amp}lt;/tr{amp}gt;' $("table").append(row ) } function disabledatr(code){ var isdisabled=event.target.value $("table #row-" code  " input").prop('disabled', (isdisabled=='true')?true:false) } 
 {amp}lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"{amp}gt;{amp}lt;/script{amp}gt; {amp}lt;table{amp}gt; {amp}lt;/table{amp}gt; {amp}lt;button id="add" onclick="add_row()"{amp}gt;add{amp}lt;/button{amp}gt;