我正在用VS2012和Javascript开发一个地铁应用程序

我想重置我的文件输入的内容:

<input type="file" id="uploadCaptureInputFile" class="win-content colors" accept="image/*" />

我该怎么做呢?


当前回答

getElementById (uploadCaptureInputFile”)的文件。价值;

其他回答

@dhaval-marthak在评论中发布的jQuery解决方案显然是有效的,但如果你看看实际的jQuery调用,就很容易看出jQuery在做什么,只是将value属性设置为空字符串。所以在“纯”JavaScript中,它将是:

document.getElementById("uploadCaptureInputFile").value = "";

jQuery的解决方案:

    $('input').on('change',function(){
                $(this).get(0).value = '';
                $(this).get(0).type = '';
                $(this).get(0).type = 'file';
            });

可以这样做

var inputfile= $('#uploadCaptureInputFile') $('#reset').on('click',function(){ inputfile.replaceWith(inputfile.val('').clone(true)); }) <script src=“https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> <input type=“file” id=“uploadCaptureInputFile” class=“win-content colors” accept=“image/*” /> <a href=“” id=“reset”>重置</a>

我用来做vuejs

   <input
          type="file"
          ref="fileref"
          @change="onChange"/>

this.$refs.fileref.value = ''

你可以克隆它,用它自己替换它,所有事件仍然附加:

<input type="file" id="control">

and

var input = $("#control");

function something_happens() {
    input.replaceWith(input.val('').clone(true));
};

谢谢:csstricks.com