入力フィールドを動的に追加しようとしていますが、これは可能です。しかし、入力フィールドに新しい名前を追加する方法がわかりません。私はそれが増加する数であることを望みます。したがって、入力フィールドの最初のグループはinput1になり、作成される各クローンは、input1、input2、input3などの番号を増やします。これを行う方法を知っている人はいますか? これがjsfiddleです:http://jsfiddle.net/liveandream/Xs7m8/
そして、ここに私のコードがあります:
HTML:
<form action="#" method="post">
<div class="avail">
<div class="roomType">
<p>Tipo de Habitación:<br />
<input type="text" name="roomType" /></p></div>
<div class="roomType">
<p><span class="small">Fecha de inicio:</span><br />
<input type="text" name="Date1" /></p></div>
<div class="roomType"><p><span class="small">Fecha de Termino:</span><br />
<input type="text" name="Date2" /></p></div>
<div class="roomType">
<p>Tarifa:<br />
<input type="text" name="roomRate" /></p></div><br clear="all" />
</div>
<input type="submit" value="+" id="copy" />
<input type="submit" value="Add to Database" name="add" />
そして私のJquery:
$("#copy").click(function(e) {
$(".avail").clone().removeAttr('id').insertBefore(this);
e.preventDefault();
});
喜んで手伝ってくれる人に事前に感謝します!!