input[type=file] 样式美化,input上传按钮美化,使用ajax上传无须控件上传文件

效果如下:

104355_oa13_175832.png

html代码如下

<form id="import-form" action="xx"
		class="formForm" method="post" enctype="multipart/form-data">
		<div class="input-append">
		<input id="fileinput" type="file" name="files" style="display: none;" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />
		 <input id="fileinput2" class="span2" type="text" />
		  <span class="btn btn-info	" onclick="$('input[id=fileinput]').click();" >
		  <i class="fa fa-folder-open"></i>选择文件</span>
		</div>
	</form>
<!--js-->
<script type="text/javascript">
$('input[id=fileinput]').change(function() {
	$('#fileinput2').val($(this).val());
});


<!--由于我的提交按钮是弹出框上的按钮,所以html代码上没有提交按钮,提交按钮代码如下-->
function dosave(){
var formData = new FormData($( "#import-form" )[0]);  
$.ajax({  
 url: 'xx' ,  
     type: 'POST',  
     data: formData,  
     async: false,  
     cache: false,  
     contentType: false,  
     processData: false,  
     success: function (returndata) {  
         alert(returndata);  
     },  
     error: function (returndata) {  
         alert(returndata);  
     }  
});   
}             	         
</script>

后台代码则看需要,举例jfinal的获取文件方式如下:

UploadFile file = getFile();
    	 List<Object[]> data = ReadExcel.read(file.getUploadPath()+"/"+file.getFileName());
    	 int row = 0;
	    for (Object[] objs : data) {
	     System.out.println(objs[1]);
	    }

 

转载于:https://my.oschina.net/bozhi/blog/735948

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值