Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用户在javascript中上载无效文件时清除输入文件字段_Javascript_Html - Fatal编程技术网

用户在javascript中上载无效文件时清除输入文件字段

用户在javascript中上载无效文件时清除输入文件字段,javascript,html,Javascript,Html,函数检查文件(发送方){ var validExts=新数组(“.jpg”、“.png”、“.gif”); var fileExt=sender.value; fileExt=fileExt.substring(fileExt.lastIndexOf('.'); if(有效索引索引of(fileExt)


函数检查文件(发送方){
var validExts=新数组(“.jpg”、“.png”、“.gif”);
var fileExt=sender.value;
fileExt=fileExt.substring(fileExt.lastIndexOf('.');
if(有效索引索引of(fileExt)<0){
警报(“选择的文件无效,有效文件为”+
toString()+“types.”);
返回false;
}
否则返回true;
}

使用
document.getElementById(“文件”).value=”“
将输入值重置为零。

如果使用jquery,可以执行以下操作:

    var $copy = $('#file');
    $('#file').remove();
    $('.wrapper').append($copy);//$('.wrapper') is the parent DOM element of input
或 您可以将这个“input”元素放在一个“form”元素中。像这样:

   <form id="myform"><input ....></form>

    document.getElementById("myform").reset(); //you can reset your input button in this way

document.getElementById(“myform”).reset()//您可以用这种方式重置输入按钮