ボタンクリックイベントのテーブルの行にある動的に追加された入力タイプフィールドを検証しようとしています。非常に最初の入力型フィールドはIDを持っているので、私はそれにバリデーションを置くことができます。しかし、テーブルに動的に行を追加すると、これらの入力タイプの検証方法がわかりません。テーブルの行に動的に追加された入力タイプを検証する
HTML:
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr>
<th class="text-center">Channel Group Name
</th>
<th class="text-center">Description
</th>
</tr>
</thead>
<tbody>
<tr id='addr0'>
<td id="CGN">
<input type="text" id="channelgrpName" name='channelgrpName' placeholder='Channel Group Name' class="form-control" />
</td>
<td id="DES">
<input type="text" id="description" name='description' placeholder='Description' class="form-control" />
</td>
</tr>
<tr id='addr1'></tr>
</tbody>
</table>
のjQuery:事前に
$(document).ready(function() {
var i = 1;
$("#add_row").click(function() {
$('#addr' + i).html("<td><input name='name" + i + "' type='text' placeholder='Channel Group Name' class='form-control' style='width:50%' /> </td><td><input name='mail" + i + "' type='text' placeholder='Description' class='form-control' style='width:50%'></td>");
$('#tab_logic').append('<tr id="addr' + (i + 1) + '"></tr>');
i++;
});
$("#delete_row").click(function() {
if (i > 1) {
$("#addr" + (i - 1)).html('');
i--;
}
});
});
$('#btnSave').click(function() {
// what should i to do here to validate dynamically added input types in row
});
感謝。
?どのタイプのバリデーションが必要なのでしょうか – Thorin
Idの代わりにクラスを使用し、クラス名と '$ this'オブジェクトを参照して検証してください。 – anu
@Thorin - ここでjqueryの検証をしたいのですが、エラー。 – N2J