关于onchange提交一次file文件的问题
2017-08-09 16:31
459 查看
1, 思想: 在没有刷新页面的时候, 默认的 file文件已经存在, 当改变的 还是原来的file文件,这个时候 onchange不在刷新
网上的做法:
1,用jQuery的live代替直接使用change
<input
name="fileToUpload" type="file" id="inputFileID" />
$("#UploadFile").live('change',
function(){ });
2:onchange后,生成一个新input type file代替旧的。 替换的原则
$('#inputFileID').replaceWith('<input name="fileToUpload" type="file" id="inputFileID" />');
我的想法:
在onchange后重置input中的value值,我把他设置为空:
我的实例:
view
js
网上的做法:
1,用jQuery的live代替直接使用change
<input
name="fileToUpload" type="file" id="inputFileID" />
$("#UploadFile").live('change',
function(){ });
2:onchange后,生成一个新input type file代替旧的。 替换的原则
$('#inputFileID').replaceWith('<input name="fileToUpload" type="file" id="inputFileID" />');
我的想法:
在onchange后重置input中的value值,我把他设置为空:
var input = document.getElementById('fileinput'); input.value='';
我的实例:
view
<input type="file" name="excel" style="position: absolute;width: 90px;height: 40px;opacity: 0; -ms-filter: 'alpha(opacity=0)';cursor:pointer;" value="" id="fileinput" onchange="fileupload()" >
js
function fileupload(){
$('#form').ajaxSubmit({
url:'',
dataType:'json',
type:'post',
data:$('#form').serialize(),
success:function(res){
var input = document.getElementById('fileinput'); input.value='';
if (res.status == 0) {
layer.msg(res.msg);
} else {
layer.msg(res.msg, {icon: 1}, function () {
location.href = '';
});
}
},
error:function(xhr, type){
layer.msg('');
var input = document.getElementById('fileinput'); input.value='';
}
});
}
相关文章推荐
- 使用input file 通过ajax 上传文件中onChange事件只触发一次问题
- 关于ajaxFileUpload造成 input[type=file] change事件只能触发一次的问题
- input type file onchange上传文件的过程中,遇到同一个文件二次上传无效的问题。
- C# 用file 上传文件大小时判断文件大小 file onchange 事件为什么只执行一次解决方案
- 一个关于OpenCV2.2静态编译时无法用cvCaptureFromFile读取文件的问题
- [已解决]关于python无法显示中文的问题:SyntaxError: Non-ASCII character '\xe4' in file test.py on line 3, but no encoding declared。
- html 应用 ajaxupload 文件控件 onchange 只能改变一次 解决方案
- 一个关于webservice的Axis问题 Processing file deploy.wsdd Exception: deploy.wsdd (系统找不到指定的文件。)
- 关于sitemap文件的设置并提交的问题!
- 关于Eclipse中通过run on server来运行JSP文件不支持session问题
- 表单包含file上传文件提交,使用ajaxSubmint或者ajaxForm 遇到的问题以及解决方法
- 文件上传(jspsmart实现)file和text表单同时提交的问题
- 关于获取<input type='file'>获取文件的路径问题
- 关于type=file;事件只执行一次的问题
- JSPSmart实现文件上传时file和text表单同时提交的问题
- input file 在开发中遇到的问题 类似ajax form表单提交 input file中的文件
- 关于onpropertychange与oninput的兼容问题
- 关于finfo_file函数获取文件mime值验证出错的问题
- 关于提交文件和提交图片时可能引发的安全问题和解决方法
- 关于File.separator 文件路径:wind与linux下路径问题 .