如何检查输入文件是空的,并且如果使用jquery选择png格式,也会显示警报 [英] How to check input file is empty, and also display an alert if png format is selected using jquery
本文介绍了如何检查输入文件是空的,并且如果使用jquery选择png格式,也会显示警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<$>c $ c>< input type =filename =filesid =file1style =color:White/>
< input type =submitvalue =Create/>
单击提交时应该触发检查。
<形式>
< input type =filename =filesid =file1style =color:White/>
< input type =submitvalue =Create/>
< / form>
和JavaScript:
点击(function(){
var fileName = $(#file1)。val();
if(fileName.lastIndexOf( (OK);
else
alert(Not PNG);
})
I have got an input file upload , need to check which file is uploaded / if no file is selected by the client using jquery.
<input type="file" name="files" id="file1" style="color:White" />
<input type="submit" value="Create" />
The check should trigger when submit is clicked.
解决方案
See the sample I have created:
<form>
<input type="file" name="files" id="file1" style="color:White" />
<input type="submit" value="Create" />
</form>
<button value="check" id="check" name="check" >check</button>
And JavaScript:
$("#check").click(function(){
var fileName = $("#file1").val();
if(fileName.lastIndexOf("png")===fileName.length-3)
alert("OK");
else
alert("Not PNG");
})
这篇关于如何检查输入文件是空的,并且如果使用jquery选择png格式,也会显示警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文