简体   繁体   中英

$(“#frm_data”)[0].reset(); Can not clear input type=file value after ajax response

i want to try reset form value on ajax success response. everything was clear instant of input type="file".

<form  id="frm_data" method="post" enctype="multipart/form-data">
   <label class="col-sm-2 control-label">Logo: </label>
   <div class="col-sm-10">
       <input type="file" name="logo" id="logo" class="styled"/>
       <br>  <br>  
   </div>
   <label class="col-sm-2 control-label">description:</label>
   <div class="col-sm-10">
        <textarea rows="5" cols="5" name="desc" id="desc" class="form-control"></textarea>
   </div>
</form>

Ajax Response

success: function(response)
    {
        $("#desc").cleditor()[0].clear();
        $("#btnSubmit").attr('value', 'Add');
        $("#frm_data")[0].reset();

    }

我看到这样

不确定文件输入是否可与reset()一起使用,但是您可以尝试分配一个空值,如下所示:

 $("#frm_data").find('[type=file]').val('');

Try this:

$('#logo').val('');

It will clear your input type file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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