我在一个页面上有几个表单,这些表单使用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)。
感谢您的帮助!
好的,我刚刚从这里的相关问题中找到了如何做到这一点:
how to use $(this) in jquery ajaxform plugin
基本上,我只需要将以下内容添加到我的 ajaxForm 函数中:
success: function(html, status, xhr, myForm) {
alert(myForm.attr('id'));
}
希望这对其他人有帮助。
最佳答案
好的,我刚刚从这里的相关问题中找到了如何做到这一点:
如何在jquery ajaxform插件中使用$(this)
基本上,我只需要将以下内容添加到我的 ajaxForm 函数中:
success: function(html, status, xhr, myForm) {
alert(myForm.attr('id'));
}
希望这对其他人有帮助。
关于jquery - 使用jQuery插件ajaxForm获取表单id并上传进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9883564/