【发布时间】:2012-04-10 15:09:44
【问题描述】:
我在一个页面上有多个表单,这些表单使用 ajaxForm 提交并显示上传进度。每个表单都具有相同的类“.input_form”、唯一的 id 和一个隐藏的输入字段,其名称和类别为“类别”,具有唯一值。 这是原始示例:http://jquery.malsup.com/form/progress.html
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('.input_form').ajaxForm({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
status.html(xhr.responseText);
$('#activity_feed_load').load(querybuild());
$('.wall_cat_selected').removeClass('wall_cat_selected');
$('.input_form, .arrow').hide();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
$('.input_form').resetForm();
}
});
在完整的函数中,我想检索提交的表单的 id 或提交的表单中隐藏字段的值。我尝试了以下方法,但没有成功。
var value = $('.input_form .category').fieldValue(); alert('The category is: ' + value[0]);
基本上,我不确定如何为提交的表单检索 ($this)。
感谢您的帮助!
好的,我刚刚从相关的 SO 问题中找到了如何做到这一点:
how to use $(this) in jquery ajaxform plugin
基本上,我只需要在我的 ajaxForm 函数中添加以下内容:
success: function(html, status, xhr, myForm) {
alert(myForm.attr('id'));
}
希望这对其他人有所帮助。
【问题讨论】:
标签: jquery jquery-plugins ajaxform