我正在使用Jquery表單驗證插件在提交之前驗證表單中的輸入,有一些輸入元素命名爲「question1」,「question2」,「question3」,...,它們是動態生成的。因此,如何驗證的jQuery插件功能驗證中),這些投入要素(?我需要一種方法來首先選擇它們。Jquery表單驗證插件,如何選擇動態生成的輸入元素進行驗證?
$(document).ready(function() {
$("#formname").validate({
rules: {
title: {
required: true,
minlength:40
},
content: {
required: true,
minlength:100,
maxlength:2000
}
},
messages: {
}
});
});
標題,內容是相同的形式內的其他投入要素,他們沒有動態生成這樣所以如何驗證「question1」,「question2」,「question3」,...,當然我可以這樣寫:
question1: {
required: true,
minlength:40
},
question2: {
required: true,
minlength:40
},
question3: {
required: true,
minlength:40
},
...
但是,正如我所說的,這些輸入元素是動態生成的,我無法預測有多少「問題」。那麼如何完成這項工作?
我想參考在 $(「#formname」)。validate({}規則:{}})函數內的那些輸入元素。 – Steven 2009-11-16 06:16:50
然後你需要一個子選擇器。我的jQuery-foo目前正在失敗,但我明天可以查找它。它就像$(「Formname question」)。validate(..等等 – 2009-11-16 07:04:53