无法使用 jQuery 验证器验证动态输入?
Can't get dynamic input to be validated with jQuery validator?
我已经阅读了关于此问题的大部分已回答问题,但直到现在还无法正常工作,2 天了,我有这个表格
<form id="mr_project_form" class="post" role="form">
<label class="fre-field-title" for="fre-project-title">Your project title</label>
<input class="input-item text-field" id="fre-project-title" type="text" name="post_title" placeholder="Add more than 15 characters"/>
<!--Submit button-->
</form>
我可以在输入元素上应用验证器,就像这样
$( "#mr_project_form" ).validate();
然后在 AJAX 调用由 AJAX 响应注入的输入后,表单将是这样的
<form id="mr_project_form" class="post" role="form">
<label class="fre-field-title" for="fre-project-title">Your project title</label>
<input class="input-item text-field" id="fre-project-title" type="text" name="post_title" placeholder="Add more than 15 characters"/>
<!--Inserted input-->
<input class="input-item text-field" id="inserted_input" type="text" name="inserted_input"/>
<!--Submit button-->
</form>
并且如 #22287410 and #18022224 中所述,我应该在添加元素后添加规则,所以在 ajax 成功中我添加了这样的规则
$.ajax({
url: mr_ajax_url,
type: "POST",
data: dataString,
success: function (response) {
$("#" + insertLcation).html(response);
$('#inserted_input').rules('add', { digit: true, });
},
});
但无法验证,我在页面加载时收到此错误
TypeError: t.validator.methods[a] is undefined; can't access its "call" property
TypeError: s is undefined; can't access its "form" property
它的 digits
与 s
,而不是 digit
。
$('#inserted_input').rules('add', { digits: true, });
我已经阅读了关于此问题的大部分已回答问题,但直到现在还无法正常工作,2 天了,我有这个表格
<form id="mr_project_form" class="post" role="form">
<label class="fre-field-title" for="fre-project-title">Your project title</label>
<input class="input-item text-field" id="fre-project-title" type="text" name="post_title" placeholder="Add more than 15 characters"/>
<!--Submit button-->
</form>
我可以在输入元素上应用验证器,就像这样
$( "#mr_project_form" ).validate();
然后在 AJAX 调用由 AJAX 响应注入的输入后,表单将是这样的
<form id="mr_project_form" class="post" role="form">
<label class="fre-field-title" for="fre-project-title">Your project title</label>
<input class="input-item text-field" id="fre-project-title" type="text" name="post_title" placeholder="Add more than 15 characters"/>
<!--Inserted input-->
<input class="input-item text-field" id="inserted_input" type="text" name="inserted_input"/>
<!--Submit button-->
</form>
并且如 #22287410 and #18022224 中所述,我应该在添加元素后添加规则,所以在 ajax 成功中我添加了这样的规则
$.ajax({
url: mr_ajax_url,
type: "POST",
data: dataString,
success: function (response) {
$("#" + insertLcation).html(response);
$('#inserted_input').rules('add', { digit: true, });
},
});
但无法验证,我在页面加载时收到此错误
TypeError: t.validator.methods[a] is undefined; can't access its "call" property
TypeError: s is undefined; can't access its "form" property
它的 digits
与 s
,而不是 digit
。
$('#inserted_input').rules('add', { digits: true, });