简体   繁体   English

无法清除文件输入

[英]Cannot clear file input

I'm using the Jasny Plugin and I'm trying to clear the file uploaded through the input: 我正在使用Jasny Plugin并且试图清除通过输入上传的文件:

<div class="form-group">
    <div class="fileinput fileinput-new text-center" data-provides="fileinput">
        <div class="fileinput-new thumbnail" data-hasqtip="1" title="" aria-describedby="qtip-1">
            <img class="image-preview" src="../assets/img/image_placeholder.jpg" alt="...">
        </div>
        <div class="fileinput-preview fileinput-exists thumbnail" style=""></div>
        <div>
            <span class="btn btn-round btn-rose btn-file">
            <span class="fileinput-new">Add Photo</span>
            <span class="fileinput-exists">Change</span>
                <input type="hidden"><input type="file" name="..." id="product-image" accept="image/*">
            </span>
            <br>
            <a href="#" class="btn btn-danger btn-round fileinput-exists" data-dismiss="fileinput">
                <i class="fa fa-times"></i> 
                Remove </a>
        </div>
    </div>
</div>

After uploaded the image, the preview appear in the box of the plugin, so I execute this code pressing a button: 上载图像后,预览显示在插件的框中,因此我按一个按钮即可执行以下代码:

$('#product-image').fileinput("clear");

but I get this error: 但是我得到这个错误:

Cannot read property 'val' of undefined
    at c.clear (jasny-bootstrap.min.js:6)
    at HTMLInputElement.<anonymous> (jasny-bootstrap.min.js:6)
    at Function.each (jquery.min.js:2)
    at r.fn.init.each (jquery.min.js:2)
    at r.fn.init.a.fn.fileinput (jasny-bootstrap.min.js:6)
    at HTMLButtonElement.dispatch (jquery.min.js:3)
    at HTMLButtonElement.q.handle (jquery.min.js:3)

Try using instead : 尝试改用:

$(".fileinput").fileinput("clear");

As you shouldn't be selecting the input inside the plugin to clear it, but rather the whole fileinput classes. 因为您不应该在插件中选择输入来清除它,而是整个文件fileinput类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM