Example on jsFiddle。
HTML:
<form>
<div class="add">
<a href="#" id="add">Add</a>
</div>
<div class="row">
<select name="roomFac1" id="roomFac1">
<option selected="selected">Any</option>
</select>
</div>
</form>
JS:
var $form = $("form"),
$firstRow = $(".row:first"),
totalRows;
$("form").on("click", ".delete", function (e) {
e.preventDefault();
$(this).closest("div").remove();
});
$("#add").on("click", function (e) {
var $clonedRow = $firstRow.clone(),
totalRows = "1",
newNum;
e.preventDefault();
totalRows = $(".row").length;
newNum = parseInt(totalRows, 10) + 1;
$clonedRow.find("select").attr("name", "roomFac" + newNum);
$clonedRow.find("select").attr("id", "roomFac" + newNum);
$clonedRow.append('<a href="#" class="delete">Delete</a>');
$form.append($clonedRow);
});
您的代碼不包含任何JavaScript的;這可能是爲什麼它不起作用= p – 2013-02-14 00:14:06