jquery - 使用jQuery插件ajaxForm获取表单id并上传进度条

标签 jquery jquery-plugins ajaxform

我在一个页面上有几个表单,这些表单使用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/

相关文章:

javascript - 如何根据类名检查元素是否存在?

javascript - jQuery Socialist 设置问题

java - jquery datatables-一个数据表中的最大列数

jquery - 我可以在按钮单击时显示/创建 jsTree 吗?

java - 如果附件不可用,ajaxform 不会提交值

jquery - 从 Struts 2 文件上传实用程序发布 ajaxForm 在 IE 中不起作用

jquery - 使一个 div 滚动到另一个 div 的前面?

javascript - 使用全选将类添加到选中的复选框

jquery - 在 jquery UI 日期选择器中突出显示日期

jquery - 使用 $ ('.ajax_form' ).ajaxForm(); 的奇怪行为