我知道有几个人可能会问这个问题,但我很难找到一个解决方案来处理我的问题。我有这样的表单,人们可以根据需要添加尽可能多的行(每行有4个输入框),然后在不使用时删除它们。我使用.append()jquery函数添加行并使其工作。使用jQuery验证动态创建的内容验证插件
我很难搞清楚如何验证新的输入框。有没有人有一个很好的解决方案,我想要做什么?这里是一个链接到我的代码:
$(document).ready(function() {
var count = 1;
$('p#add_field').click(function() {
count += 1;
$('table#entries').append(
'<tr>' +
'<td><input id="cl_' + count + '" name="cl[]' + '" type="text" /></td>' +
'<td><input id="num_' + count + '" name="num[]' + '" type="text" size="5"/></td>' +
'<td><input id="description_' + count + '" name="description[]' + '" type="text" size="86"/></td>' +
'<td><span class="delete">Remove</span></td></tr>');
$(".delete").click(function() {
$(this).closest('tr').remove();
});
});
// 1. prepare the validation rules and messages.
var rules = {
email: {
required: true,
email: true
},
lname: "required",
fname: "required",
city: "required",
address: "required",
'cl[]': "required",
'num[]': "required",
'description[]': "required",
age: {
required: true,
number: true,
maxlength: 3
},
phone: {
required: true,
phoneUS: true
}
}; // end var rules
// 2. Initiate the validator
var validator
= new jQueryValidatorWrapper("FormToValidate",
rules);
// 3. Set the click event to do the validation
$("#btnValidate").click(function() {
if (!validator.validate())
return;
alert("Validation Success!");
});
});
这非常有意义!感谢您的帮助和时间!对此,我真的非常感激! – user2191829 2013-03-26 14:23:43
@ user2191829,不客气。另外,请不要忘记点击绿色的选中标记“接受”我的答案。谢谢。 – Sparky 2013-03-26 16:33:07