如何检查输入文件是空的,并且如果使用jquery选择png格式,也会显示警报 [英] How to check input file is empty, and also display an alert if png format is selected using jquery

查看:124
本文介绍了如何检查输入文件是空的,并且如果使用jquery选择png格式,也会显示警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <$> 

c $ c>< input type =filename =filesid =file1style =color:White/>
< input type =submitvalue =Create/>

单击提交时应该触发检查。



> http://jsfiddle.net/G7xke/






 <形式> 
< 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:

http://jsfiddle.net/G7xke/


<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆