私はこのhtmlを持っています
<form method="POST" action="" id="order" class="forms">
<div>
<span class="col1">Ref.</span>
<span class="col2">Number</span>
<span class="col3">Color</span>
<span class="col4">Remarks</span>
<span class="col5">Prijs</span>
</div>
<div class="order">
<input type="text" name="ref-1" class="col1" />
<input type="text" name="num-1" class="col2" />
<input type="text" name="color-1" class="col3" />
<input type="text" name="remark-1" class="col4" />
<input type="text" name="price-1" class="col5" />
</div>
<a id="add" href="#">+</a>
</form>
そしてこのjquery
$("#add").click(function() {
$("#order").children(":eq(1)").clone().each(function() {
var index = $("#order").children().length - 1;
alert(index);
$(this).children().find(":input").each(function() {
alert(index);
$(this).attr("[name]", function(i, v) {
return v.substr(0, v.lastIndexOf("-") + 1) + index;
}).val("");
});
}).insertBefore("#add");
});
各入力名の-1の部分を増分値に置き換える必要があります。しかし、jsが$(this).attr()
関数に到達することはありませんこのコードを実行すると、クリックしたときに2番目のアラートボックスが表示されません#add