How to clear File Input

前端 未结 11 1075
臣服心动
臣服心动 2020-12-13 05:10

Below is part of the jquery code I have which displays the file input and a \"Clear File\" button.

var $imagefile = $(\'\').attr({
    type: \         


        
11条回答
  •  醉酒成梦
    2020-12-13 06:08

    This is the method I like to use as well but I believe you need to add the bool true parameter to the clone method in order for any events to remain attached with the new object and you need to clear the contents.

        var input = $("#fileInput");
    
        function clearInput() {
            input = input.val('').clone(true);
        };
    

    https://api.jquery.com/clone/

提交回复
热议问题