快速问题:如何使用好的、旧的jQuery Validate来验证在页面加载后添加到DOM (通过Ajax)的表单?
$("form#superForm").validate(options);不工作..。
谢谢!
发布于 2011-08-16 20:12:30
$("form#superForm").validate(options);可以正常工作。只是您试图在加载内容(form#superForm)之前附加它。
如果你想让它正常工作,你必须在加载之后附加它。所以,举个例子:
$('#somediv').load('path/to/ajax/that/returns/form#superForm', function() {
$("form#superForm").validate(options);
});发布于 2011-08-16 20:12:29
$("form#superForm").validate(options);不工作...
它将会工作,您只需在表单添加到DOM之后调用它,该DOM位于AJAX调用的成功回调中。我猜想当表单还不存在于DOM中时,您将在document.ready中调用它。
例如:
$(function() {
// when some button is clicked we load the form:
$('.button').click(function() {
// we send an AJAX request to load the form
$.post('/somescript', function(result) {
// the AJAX request succeeds and we inject the result into the DOM:
$('#result').html(result);
// now we can attach the validator:
$('#superForm').validate(options);
});
return false;
});
});https://stackoverflow.com/questions/7078012
复制相似问题