uploadify如何获取我按下的按钮的ID

时间:2015-03-25 08:39:40

标签: javascript uploadify

我想要点击我在这里按下的按钮

 $(".J-fileup").uploadify({
     'formData': {},
         'swf': '/assets/uploadify/uploadify.swf',
         'uploader': '/admin/resource/upload',
         'cancelImg': '/assets/uploadify/uploadify-cancel.png',
         'onUploadSuccess': function (file, data, response) {
         var data = JSON.parse(data);
         if (data.status == 1) {
             //--I want id of the button that I pressed here
         }
     }

 });

3 个答案:

答案 0 :(得分:0)

您甚至可以使用:

$(".J-fileup").each(function() {
  var $jfileup = $(this);
  // Now you can use $jfileup.attr('id') to get the id.
  $jfileup.uploadify({
     'formData': {},
         'swf': '/assets/uploadify/uploadify.swf',
         'uploader': '/admin/resource/upload',
         'cancelImg': '/assets/uploadify/uploadify-cancel.png',
         'onUploadSuccess': function (file, data, response) {
         var data = JSON.parse(data);
         if (data.status == 1) {
             // use $jfileup.attr('id')
             //--I want id of the button that I pressed here
         }
     }

 });
});

答案 1 :(得分:0)

您可以执行以下操作:

'onUploadSuccess': function (file, data ,response,event) {
  var data = JSON.parse(data);
        if (data.status == 1) {
             var buttonId = event.target.id;
             if(typeof buttonId!= 'undefined'){
                  //Do what you want to do here.
             } 

         }
 }   

答案 2 :(得分:0)

使用 uploadify onSelect回调:

'onSelect': function(event, ID, fileObj) {
  var triggerId = $(event.target).attr("id"); //here you get the id of the object.
},