更新时间:2022-10-28 11:55:16
您要添加ID字符串规则,而不是元素选择器,然后将规则添加到该选择器.
You are adding rule taking ID string.Instead take the element selector, and add rule to that selector.
var $largestID = $("#to-append > div:last > div:first > input:first").attr("id");
console.log($largestID); //throws right id
$('#'+$largestID).each(function () {
$(this).rules('add', {
requzired: true,
minlength: 3,
pattern: yt
});
});
使用$('#'+ $ largestID)获取该ID的字段,然后添加规则.
Use the $('#'+$largestID) to get the field of that ID, and then add rules.
要向数组添加规则,请使用
To add rules to array, use
$('#'+$largestID) .each(function () { }
您甚至可以验证该元素的名称数组,
you can even validate the array of names of that element,
$('#'+$largestID).validate({
rules: {
'url[]': {
required: true,
}
}
});