JSFiddle - React, Tailwind, and code Playground

by pomansur

HTML

<table id="club" class="table table-striped table-bordered table-hover">
<tbody></tbody>
<tfoot>
<tr>
<td class="text-left"><button type="button" onclick="addClub();" data-toggle="tooltip" title="Добавить" class="btn btn-primary">++</button></td>
</tr>
</tfoot>
</table>

JavaScript

club_row = 0;
function addClub() {
html  = '<tr id="club-row' + club_row + '">';
html += '  <td class="text-left"><select name="product_club[' + club_row + '][customer_group_id]" class="form-control">';
html += '      <option value="1">хаха</option>';
html += '      <option value="">хохо</option>';
html += '  </select></td>';
html += '  <td class="text-left"><input type="checkbox" name="product_club[' + club_row + '][club]" value="1" /></td>';
html += '<td class="text-left"><input type="text" name="product_club[' + club_row + '][club_descr]" value="описание" placeholder="описание" class="form-control" /></td>';
html += '</tr>';
$('#club tbody').append(html);

		$('#club-row' + club_row + '').focusin(function(){
			alert("-------"+club_row);//  выводит каким то образом переменную club_row, но в строку что ниже не подставляет
      // если в строку ниже подставить значение club_row ,допустим 0, то второй алерт срабатывает
			$('select[name="product_club[' + club_row + '][customer_group_id]"] option:selected').each(function(){
      	 alert("+++++++"+club_row); // не видна переменная
   		});
		});
	club_row++;
}