我在一个页面上有几个表单,它们使用 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 问题中找到了如何做到这一点:
如何在 jquery ajaxform 插件中使用 $(this)
基本上,我只需要将以下内容添加到我的 ajaxForm 函数中:
success: function(html, status, xhr, myForm) {
alert(myForm.attr('id'));
}
希望这对其他人有帮助。