没有从使用JQuery和Javascript的文件输入HTML控件获取[Object File] [英] Not getting [Object File] from a File Input HTML Control using JQuery and Javascript

查看:2367
本文介绍了没有从使用JQuery和Javascript的文件输入HTML控件获取[Object File]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件输入控件按钮如下: -

 < input type =filename =Resumeid =upload>< / input> 
< input type =buttonid =btnSavevalue =Saveonclick =sample()>< / input>

另外一个叫做 sample()

 < script type =text / javascript> 
函数sample(){
var file = $('#upload')[0] .files [0];
alert(file);
}
< / script>

通过点击 btnsave
$ p code $不会返回 [object File] ,尽管在​​文件输入控制文件存在。



注意:我使用 IE 11 并加载了Jquery库。

解决方案

您可能遇到以下问题:导致IE模拟旧版本的本地Intranet 区域。尝试在< head>内添加这行作为第一个条目标记:

 < meta http-equiv =X-UA-Compatiblecontent =IE = edge/> 

来自Microsoft: https://msdn.microsoft.com/zh-CN/library/jj676915.aspx


I have a file input control and button as below:-

<input type="file" name="Resume" id="upload"></input>
<input type="button" id="btnSave" value="Save" onclick="sample()"></input>

Also a function called as sample()

<script type="text/javascript">
    function sample(){
    var file =$('#upload')[0].files[0];
    alert(file);
    }
</script>

The above function is called on a click of button btnsave.

Issue:Does not return a alert with [object File], inspite of file exist in file input control.

Note: I am using I.E 11 and also loaded Jquery library.

解决方案

You might be experiencing an issue in which the site you are working on is listed in your Local Intranet zone which causes IE to emulate an older version. Try adding this line as the very first entry within your <head> tag:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

From Microsoft: https://msdn.microsoft.com/en-us/library/jj676915.aspx

这篇关于没有从使用JQuery和Javascript的文件输入HTML控件获取[Object File]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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