jQueryのcloneを使用してテーブルの中のTRタグ2行分をコピーしようとしているのですが、2行目のインプット部分だけ入力欄が表示されません。
どこか間違っているでしょうか
宜しくお願い致します。
<body>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).on("click", "[id='addrow']", function(e) {
var max_no = $( '#sample_table > tbody > tr:last td:first' ).html();
var next_no = parseInt(max_no) + 1;
$("#sample_table > tbody > tr:lt(2)").clone(true).appendTo(
$("#sample_table > tbody")
);
$( '#sample_table > tbody > tr:gt(2)' ).css('display', '');
$( '#sample_table > tbody > tr:last td:first' ).html(next_no);
$( '#sample_table > tbody > tr:last > td > input' ).each(function() {
var base_name = $(this).attr('name');
$(this).attr('name', base_name + "_" + next_no);
});
});
</script>
<form>
<button type="button" id="addrow">行追加</button>
<table id="sample_table" border="1">
<thead>
<tr>
<th>No</th>
<th>タイプ</th>
<th>名称</th>
</tr>
</thead>
<tbody>
<tr style="display:none;">
<td id="next_no" rowspan="2">1</td>
<td><input type="text" name="type" value=""></td>
<td><select name="sample1">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select></td>
</tr>
<tr style="display:none;">
<td><input type="text" name="type" value=""></td>
<td><select name="sample2">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select></td>
</tr>
<tr>
<td rowspan="2">1</td>
<td><input type="text" name="type_1"></td>
<td><select name="sample3">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select></td>
</tr>
<tr>
<td><input type="text" name="type_2"></td>
<td><select name="sample4">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select></td>
</tr>
</tbody>
</table>
</form>
</body>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/08 07:52