在我的工作我曾經回答這個問題:如何驗證JQuery的克隆形式
JQuery clone form and increment
如何驗證克隆使用jQuery驗證表單?
我嘗試以下,但它沒有工作:
$(document).ready(function() {
$(function() {
var template = $('#attendees .attendee:first').clone(),
attendeesCount = 1;
var addAttendee = function() {
attendeesCount++;
var nativeTemplate = template.clone();
var attendee = nativeTemplate.find(':input').each(function() {
var newId = this.id.substring(0, this.id.length - 1) + attendeesCount;
$(this).prev().attr('for', newId); // update label for (assume prev sib is label)
this.name = this.id = newId; // update id and name (assume the same)
}).end() // back to .attendee
.attr('id', 'att' + attendeesCount) // update attendee id
.prependTo('#attendees') // add to container
.validate(
// rules
);
};
$('.add').click(addAttendee); // attach event
});
});