我正在将动态HTML内容带到另一个HTML内容中。这基本上是一个编辑表单HTML视图,但是当我尝试验证表单时,它会给出“TypeError: jQuery(...).validate不是函数”错误。我正在使用jQuery 1.6.2版本。
function validate_edit_venue() {
jQuery('#venue_edit_form').validate({
rules: {
venueName: {
required: true,
minlength: 1,
maxlength: 50
},
venueDescription: {
required: false,
lettersonly: true,
maxlength: 150
},
venueType: {
required: true
}
},
messages: {
venueName: {
required: "Venue name is required",
minlength: "Minimum 1 character required",
maxlength: "Should not exceed 50 characters"
},
venueDescription: {
maxlength: "Should not exceed 150 characters"
},
venueType: {
required: "Please select a venue type"
}
}
});
}
这是我的jQuery验证。我在jQuery编辑表单脚本中调用此函数。有人能帮我解决这个问题吗?这个问题可能是重复的,但大多数问题都是由于jQuery版本问题引起的,所以我无法通过它们获得恰当的答案。
jQuery('#venue_edit_save').live('click', function(){
validate_edit_venue();
if(jQuery("#venue_edit_form").valid())
{
var directory_id = jQuery(this).attr('directory_id');
var venue_type = jQuery(this).attr('venue_type');
var venueName = jQuery('#venue_name').val();
var venueDescription = jQuery('#description').val();
var venueType = jQuery('#venue_types option:selected').val();
var venueImage = jQuery('[name="profile_image'+directory_id+'"]').val();
jQuery.blockUI();
jQuery.ajax({
type: 'POST',
cache: false,
dataType: 'json',
url: baseurl+'catalog/catalog/action/venues/edit_venue',
data:{'directory_id':directory_id,'venueName':venueName,'venueDescription':venueDescription,'venueType':venueType,'venueImage':venueImage},
success: function(data)
{
if(data.status == 'success')
{
/*if(venue_type == venueType)
{
jQuery('#Venue_'+directory_id).replaceWith(data.html);
}
else
{
location.reload();
}*/
jQuery('#Venue_'+directory_id).replaceWith(data.html);
show_messages(data.status,data.msg);
setTimeout(jQuery.unblockUI);
jQuery('#edit-dining-venue-block').hide();
location.reload();
}
else if(data.status == 401)
{
redirect_login_timed_out();
}
/*else
{
show_messages(data.status,data.msg);
setTimeout(jQuery.unblockUI);
jQuery('#edit-dining-venue-block').hide();
}*/
},
error:function (jqXHR)
{
if(jqXHR.status == 401)
{
redirect_login_timed_out();
}
setTimeout(jQuery.unblockUI);
}
});
}
});
// Hiding the edit venue view when clicking the cancel button
jQuery('#venue_edit_cancel').live('click', function(){
jQuery('#edit-dining-venue-block').hide();
});
});
这是出现错误的位置。这个jQuery会在验证时保存编辑后的信息。
谢谢。