jquery
2012-03-02 75 views 0 likes 
0

HTML:
清除上傳的文件名

<input type="file" id="flIcon" /> 

jQuery中:

$('#btnAddNew').click(function(event) { 
        alert($("#flIcon").attr('file')); 
        $("div#flIcon").replaceWith("<input type='file' id='flIcon'/>"); 

       }); 

我螢火看到當頁面加載:

<div id="uniform-flIcon" class="uploader"> 
<input id="flIcon" class=" " type="file" style="opacity: 0;"> 
<span class="filename" style="-moz-user-select: none;">document-save.png</span> 
<span class="action" style="-moz-user-select: none;">Choose File</span> 
</div> 

我試試吧從這個參考。 Clearing <input type='file' /> using jQuery但它不適合我。是否有任何瀏覽器兼容性問題或我錯過了一些東西。謝謝。

+0

其工作罰款$( 「#flIcon」)replaceWith( '..')。這裏--- http://jsfiddle.net/XFyuw/3/ – mini 2012-03-02 07:32:14

+0

$('#btnAddNew')。on('click(function(event){alert($(「#flIcon」)。attr('file' )); $(「div#flIcon」)。replaceWith(「」);}); – Ohgodwhy 2012-03-02 07:34:44

回答

1

嘗試這樣的:

<input type="file" id="flIcon" /> 
<div id="btnAddNew">Clear</div> 

然後:

$('#btnAddNew').click(function(event) { 
    $("#flIcon").replaceWith("<input type='file' id='flIcon'/>").html(); 
});​ 
0

是Darin的解決方案效果很好。

另外,您還可以通過這樣使用JQuery清楚..

$('#flIcon').val(''); 
相關問題