站长资讯网
最全最丰富的资讯网站

jquery如何判断 input type="file"上传文件是否为空

jquery判断 input type="file"上传文件是否为空的方法:使用html上传按钮,代码为【<button type="button" onclick="submitXML()">提交</button>】。

jquery如何判断 input type=&quot;file&quot;上传文件是否为空

本教程操作环境:windows7系统、jquery3.2.1版本,DELL G3电脑,该方法适用于所有品牌电脑。

推荐:jquery视频教程

jquery判断 input type="file"上传文件是否为空的方法:

要想获取type="file"的input内容,用var file = $("id").val();肯定是不行的,下面是代码:

html上传按钮为:

<input type="file" id="reportXML" name="reportXML" title="输入内容" multiple="multiple"> <button type="button" onclick="submitXML()">提交</button>

js代码:

function submitXML(){ var fileInput = $('#reportXML').get(0).files[0]; console.info(fileInput); if(fileInput){ $("#reportXMLform").submit(); }else{ alert("请选择上传文件!"); } }

相关免费学习推荐:js视频教程

赞(0)
分享到: 更多 (0)

网站地图   沪ICP备18035694号-2    沪公网安备31011702889846号