2014-05-11 40 views
3

我读了很多关于如何删除NO file selected文本的讨论。删除没有根据条件选择的文件

我发现这招做的工作,但我需要的东西有点不同:

<style type="text/css">  
    input[type='file'] { 
     color: transparent; 
    } 
</style> 

<input type="file" /> 

我需要NO file selected以根据if条件被删除

喜欢的东西if there is a value然后取出没有选择文件,否则添加它。

@if (Model.value != null) 
{ 
    Remove the no file chosen 
} 
else 
{ 
    Add the no File chosen 
} 

这可能吗?我用MVC5项目...

+0

可能重复[我怎样才能把一个文件输入“无文件选择”工具提示中Chrome?](http://stackoverflow.com/questions/12035400/how-can-i-remove-the-no-file-chosen-tooltip-from-a-file-input-in-chrome) – undefined

+0

@ undefined-没有它,因为我已经阅读它,而不是基于条件... –

+0

添加一个条件不是很难(如果这是唯一的问题)。 – undefined

回答

1

您可以使用CSS类和这个有点JS的:

@if(Model.value != null){ 
    <input type="file" onchange="fileOnchange(this)" class="notext"/> 
    <script> 
     function fileOnchange(el){ 
     if(el.value){ 
      el.className = ""; 
     } 
     else{ 
      el.className = "notext"; 
     } 
     } 
    <script/> 
    <style type="text/CSS"> 
    .notext{ 
     color: transparent; 
    } 
    <style/> 
    } 
    else 
    { 
    <input type="file" /> 
    } 
+1

非常感谢你这是工作:) !!!! –

+0

不客气!祝你好运! –