上传表格input【type="file"】
2017-12-04 17:35
316 查看
<script type="text/javascript">
//验证上传的格式
function clickFileName(upload_field) {
var filename = upload_field.value;
var newFileName = filename.split('.');
newFileName = newFileName[newFileName.length-1];
if (/^(xls|xlsx|XLS|XLSX)$/.test(newFileName)==false) {
alert("上传的文件格式只能为Excel格式(2003或者2007版本的)");
upload_field.form.reset();
return false;
}
}
//提交前验证提交的数据
function verityFile(){
if($("#userfile").val()==null||$("#userfile").val()==''||$("#userfile").val()=="undefined"){
alert("请选择文件导入!");
return false;
}
var lockFlag = isLock();
if (lockFlag){
alert('已有数据正在导入,请稍后再试!');
return false;
}
return true;
}
//判断是否有数据正在导入
function isLock(){
var isLock = false;
$.ajax({
type:"post",
async:false,
url:"<%=basePath%>propertyPayment_Payment_importPropertyInfoLock.do",
success:function(data,status){
if(status && data == '0'){
isLock = true;
}
}
});
return isLock;
}
</script>
<table width="610px" border="0" cellpadding="1" cellspacing="0">
<tr>
<td width="100%">
<form id="uploadForm" name="uploadForm" method="post" enctype="multipart/form-data" action="***_Payment_importPropertyInfo.do" onsubmit="return verityFile()">
<table id="personal_table" border="0" cellpadding="2" cellspacing="1" width="100%" align="center" style="">
<tr style=" COLOR: #000;" >
<td width="10%">文件上传:</td>
<td width="63%">
<input type="file" id="userfile" name="userfile" onchange="clickFileName(this)" >
</td>
</tr>
<tr >
<td nowrap="nowrap" ></td>
<td >
<input class="input_img" type="submit" value="提交"/>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
//验证上传的格式
function clickFileName(upload_field) {
var filename = upload_field.value;
var newFileName = filename.split('.');
newFileName = newFileName[newFileName.length-1];
if (/^(xls|xlsx|XLS|XLSX)$/.test(newFileName)==false) {
alert("上传的文件格式只能为Excel格式(2003或者2007版本的)");
upload_field.form.reset();
return false;
}
}
//提交前验证提交的数据
function verityFile(){
if($("#userfile").val()==null||$("#userfile").val()==''||$("#userfile").val()=="undefined"){
alert("请选择文件导入!");
return false;
}
var lockFlag = isLock();
if (lockFlag){
alert('已有数据正在导入,请稍后再试!');
return false;
}
return true;
}
//判断是否有数据正在导入
function isLock(){
var isLock = false;
$.ajax({
type:"post",
async:false,
url:"<%=basePath%>propertyPayment_Payment_importPropertyInfoLock.do",
success:function(data,status){
if(status && data == '0'){
isLock = true;
}
}
});
return isLock;
}
</script>
<table width="610px" border="0" cellpadding="1" cellspacing="0">
<tr>
<td width="100%">
<form id="uploadForm" name="uploadForm" method="post" enctype="multipart/form-data" action="***_Payment_importPropertyInfo.do" onsubmit="return verityFile()">
<table id="personal_table" border="0" cellpadding="2" cellspacing="1" width="100%" align="center" style="">
<tr style=" COLOR: #000;" >
<td width="10%">文件上传:</td>
<td width="63%">
<input type="file" id="userfile" name="userfile" onchange="clickFileName(this)" >
</td>
</tr>
<tr >
<td nowrap="nowrap" ></td>
<td >
<input class="input_img" type="submit" value="提交"/>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
相关文章推荐
- 关于JFinal的单个input标签type=file的multiple="multiple"多图片上传,每次只接收到一个uploadFile对象的解决办法。
- android webview使用html5<input id="input" type="file"/> 上传相册、拍照照片
- 上传文件 隐藏input type="file",用其它标签实现
- html中,文件上传时使用的<input type="file">的样式自定义
- 用jQuery重置用于文件上传的input (type="file")
- 手机浏览器<input type="file">标签调用手机拍照+分片上传
- 处理同一页面中借助form+input[type="file"]上传图片出现的input无法清空问题
- input type="file"文件上传时得到文件的本地路劲
- JS清空上传控件input(type="file")的值的代码第1/2页
- angularjs上传 和 <input type="file">与ng-model 的玩法
- 使用<input type="file">实现文件上传
- 文件上传input type="file"样式美化
- js 实现 <input type="file" /> 文件上传
- 上传文件控制input type="file"样式修改记
- 上传按钮样式优化 <input type="file" />
- 将通过<input type="file">上传的txt文件存储在localStorage,提取并构建File对象
- 修改input[type="file"]文件上传样式的2种方法
- asp.net/c# 用<input type="file" />实现文件上传,multipart/form-data
- 自定义 input type="file" 文件上传样式
- Android:让WebView支持<input type="file"…>元素,实现文件上传