2014-02-17 40 views
-1

我的看法我要檢查文件是否大於500 KB給例如警報()GET大小

<img src="@Model.Value" width="95" height="80" id="down-load" data-id="@Model.Key" data upload="@Url.Action("AddPreview", "Images")" />

(function ($) { 
$("[data-id]").each(function() { 
    var $this = $(this); 
    $($this).upload({ 
     name: 'attachments', 
     action: $this.data("upload"), 
     enctype: 'multipart/form-data', 
     params: {}, 
     autoSubmit: true, 
     onSubmit: function() { }, 
     onSelect: function() { 
     var size = $('#down-load')[0].files[0].size;//do not work 

     }, 
     onComplete: function (e) { 
      if (e.charAt(0) != '[') { 
       $.fn.showUserActionNotification(e, true); 
       return; 
      } 

      var data = JSON.parse(e); 
      if (data[0].Error) { 
       $.fn.showUserActionNotification(data[0].Error, true); 
      } 
      else if (data[0].Preview) { 
       $this.attr("src", data[0].Preview); 
      } 
     } 
    }); 

    $this.parent().find("input").css("cursor", "pointer"); 
}); 
})(jQuery); 

我想獲得功能ONSELECT尺寸檢查大 任何機構都可以幫助我嗎?

+1

可能出現的重複是在這裏:http://stackoverflow.com/questions/1601455/check-file-input-size-with-jquery/3937404#3937404 – Pavlo

+0

看起來像你應該使用它像:$('#down-load')。files [0] .size – Pavlo

+0

此功能沒有文件 – user246340

回答

0

我已經做了功能

var imageSize = function (e) { 
return $.map(e.files, function (file) { 
    var name = file.name; 
    var size = file.size; 

    if (size > 512000) { 
     var alert = $(".valid-size-goods").text(name + ": " + (size/1024).toFixed(2) + " kb"); 
     alert.dialog({ 
      title: alert.attr("dlgTitle"), 
      modal: true, 
      resizable: false, 
      buttons: [{ text: alert.attr("btn"), click: function() { $(this).dialog("close"); } }] 
     }); return false; 
    } 
    return true; 
}); 

};

,並把它ONSELECT:IMAGESIZE(E)