我有很多形式,創造了jQuery驗證()
我有這樣的HTML
<form method="post" id="form_commento-[i]" class="form_fancybox_commenti">
<div class="form-section">
<span style="position: relative">
<input type="text" id="commento_form_[i]_commento" name="commento_form_[i][commento]" required="required"/>
<button type="submit" class="submit-button" id="submit_form_commenti">Commenta</button>
</span>
</div>
</form>
在哪裏[i]是指數
在我的文檔準備好我有
$(document).ready(function() {
jQuery.validator.addMethod("alphanumeric", function (value, element) {
return this.optional(element) || /^[a-zA-Z0-9\n\-'àèìòù: <_,. !?()]*$/.test(value);
}, "error");
$('.form_fancybox_commenti').each(function(index, numero_form) {
var theRules = {};
theRules[
'commento_form_['+index+'][commento]'] = {alphanumeric: true};
$(this).validate({
rules: theRules,
submitHandler: function(form) {
save(form);
}
});
});
但我的自定義規則不起作用。
無論如何要解決這個問題?
什麼是您的JavaScript控制檯告訴你嗎? – Sparky