如何获取单击元素的表单对象

时间:2011-10-09 07:17:28

标签: php javascript jquery file-upload uploadify

我使用jQuery uploadify插件上传文件。 Each time I upload a file, a hidden field is created in the form with uploaded file path on server.当我提交表单时,我将此文件路径存储在数据库中,方法是从隐藏字段中获取它。它对我有用。一个问题是我很难在uploadify的onComplete函数中编写表单对象。

这是我的代码:

jQuery的:

     $('.FileUpload').uploadify({
        'uploader'  : '/uploadify/uploadify.swf',
        'script'    : '/uploadify/uploadify.php',
        'cancelImg' : '/uploadify/cancel.png',
        'folder'    : '/uploads',
        'auto'      : true,
        'queueID'   : 'fileQueue',
        'removeCompleted':false,
        'onComplete'  : function(event, ID, fileObj, response, data) {
                            // It is hard coded here. It may create probelems 
                            // if there are multiple file upload buttons.
                            // How can I do this with '$(this)' keyword or something
                            $('.SingleFileUpload').parents('form').append( '<input type="hidden" name="uploaded_file" value="' + response + '">' );
                        }
      }); 

如何才能在onComplete()功能中仅点击表单的文件浏览按钮。我觉得你明白了吗?

谢谢

2 个答案:

答案 0 :(得分:2)

如果您将$('.SingleFileUpload')替换为$(event.target)

,我认为它应该有用

答案 1 :(得分:0)

我使用以下方法解决了我的问题:

$(event.target).closest('form').append( '<input type="hidden" name="uploaded_file" value="' + response + '">' );
相关问题