开发者

jQuery: how to clear context of a FileUpload control of asp.net

I know to clear context of a textbox, using $('#textbox1').val(""); But how to clear context of a FileUpload control. I mean to erase the content of it's textbox. For example, I first choose a file using FileUpload control, which it shows c:\user\1.png. Now I want to clear it by using jQuery.

$('#FileUpload1').val(""); 

apprently does not开发者_JAVA百科 work here.


$('#FileUpload1').val("");

won't work on ie.

document.getElementById("#FileUpload1").createTextRange().execCommand('delete');` will work on ie

or you can use
var file = document.getElementById("<%=FileUpload1.ClientID%>"); $(file).parent().html($(file).parent().html());


$('#FileUpload1').val(""); 

you're missing '


Your FileUpload control will be rendered as a div with an input of type "file" and a client ID determined by your ClientIDMode. In many circumstances, it will be the same as your control's server-side ID.

There's an excellent explanation of how ASP.net generates client-side IDs from server-side ones here

(Or, you could just be missing a closing quote.)


might try this

<input type="file" id="control"/>
<button id="clear">Clear</button>
var control = $("#control");

$("#clear").on("click", function () {
    control.replaceWith( control = control.clone( true ) );
});

http://jsfiddle.net/jonathansampson/dAQVM/

taken from here : Clearing <input type='file' /> using jQuery

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜