是否有可能清除<input type='file' />控件值与jQuery?我试过以下几种方法:
$('#control').attr({ value: '' });
但这并不奏效。
是否有可能清除<input type='file' />控件值与jQuery?我试过以下几种方法:
$('#control').attr({ value: '' });
但这并不奏效。
当前回答
$("#control").val(")就是你所需要的!使用JQuery 1.11在Chrome上测试
其他用户也在Firefox中进行了测试。
其他回答
我能够得到我的工作与以下代码:
var input = $("#control");
input.replaceWith(input.val('').clone(true));
一个简单的方法是改变输入类型,然后再把它改回来。
就像这样:
var input = $('#attachments');
input.prop('type', 'text');
input.prop('type', 'file')
最后我得出了这个结论:
if($.browser.msie || $.browser.webkit){
// doesn't work with opera and FF
$(this).after($(this).clone(true)).remove();
}else{
this.setAttribute('type', 'text');
this.setAttribute('type', 'file');
}
也许不是最优雅的解决方案,但据我所知它很有效。
这对我很有用。
$("#file").replaceWith($("#file").clone());
http://forum.jquery.com/topic/how-to-clear-a-file-input-in-ie
希望能有所帮助。
我的火狐40.0.3只支持这个功能
$('input[type=file]').val('');
$('input[type=file]').replaceWith($('input[type=file]').clone(true));