2014-04-19 28 views
1

我正在使用jquery fileupload来处理asp.net mvc的项目。 其工作正常,但只有一个问题是,在选择文件后,文件名不显示,仍然显示'没有选择文件'。如何在'没有选择文件'的地方显示文件名。我使用data.files [0] .name获得了文件名,但是如何显示,我使用usinf输入类型是文件控制。如何在jquery文件上传中显示名为'No file selected'的细节

我的控制是

<input type="file" id="ItemImages" accept="image/*" name="uploadfile" data-val="true" data-val-required="please select a file" class="fileupload-new"> 

和我的代码是

$('imffileuplod').fileupload({ 
     dataType: 'json', 
     dropZone: null, 
     url: DomainName + "BackOffice/" + MethodName, 
     progressInterval: 10, 
     bitrateInterval: 50, 
     add: function (e, data) { 
      try { 

       var imageKbytes = parseFloat(data.files[0].size/1024); 
       var ImageMbytes = parseFloat(imageKbytes)/1024; 
       if (ImageMbytes > parseFloat(2.0)) { 
        $("#errormessage").text("Please upload image upto 2 MB only"); 
        return; 
       } 
       alert(data.files[0].name); 

       $("#errormessage").text(""); 
       $('#progress .bar').text(''); 
       $('#progress .bar').css('width', '0%'); 


       $('#progress .bar').show(); 
       data.submit(); 

      } 
      catch (ex) { 
       OpenAlertDialog(ex.message); 
      } 

     }, 
     done: function (e, data) { 
      $('#progress .bar').css("width", "100%"); 
      $('#progress .bar').text('100%'); 

      $("#" + ImageSrcId).attr("src", data.result); 

      setTimeout(function() { 
       $('#progress .bar').css("width", "0%"); 
       $('#progress .bar').text(''); 
      }, 3000); 
      // $("#ProgressSpan").text(''); 

     }, 
     Fail: function (e) { 
     } 
    }); 
} 

选择imaage它仍然显示 '未选择文件' 后

enter image description here

回答

1

你不能改变的价值输入类型文件使用Js,但可以采取独立的div下面,并显示文件名在里面。

if you work with ´jquery 1.8´, the selector ´type=file´ works correctly but if you work with ´jquery 1.6´ this selector will not work. the correct way is to use this type of selectors: 

$('input[type="file"]') 
or, you can use this type selector, with class: 

HTML: 

<input class="input-type-file" type="file" name="file_1" enctype="multipart/form-data" /> 
JS: 

$('.input-type-file') 
+0

我正在使用jquery 1.8.3 –

+0

相关问题