$(function () { $("#confirm").on("click",function(){ var files = $("input").eq(0).val(); if(files==""){ alert("ÇëÏÈÉÏ´«Îļþ"); } }); $("#cancel").on("click",function(){ // webform.close(); }); $("#fileUpload").change(function(){ var val = $(this).val(); var fileName = val.split("\\")[val.split("\\").length-1]; if (val.indexOf("xls") != -1 || val.indexOf("xlsx") != -1) { $("input").eq(0).val(fileName); $('#formFile').ajaxSubmit({ url:'excel_targetFile.action', type:'POST', // data:{scmd:''}, ÐèÒª´«Ê²Ã´²ÎÊý×Ô¼ºÅäÖà success:function(data){ $("#confirm").on("click",function(){ alert("µ¼Èë³É¹¦"); }); $("#cancel").on("click",function(){ alert("È¡Ïûµ¼Èë"); }); }, error:function(xhr){ alert("ÉÏ´«³ö´í"); } }); } else { alert("ÇëÑ¡ÔñÕýÈ·µÄÎļþ¸ñʽ£¡"); //Çå¿ÕÉÏ´«Â·¾¶ $(this).val(""); return false; } }); })
¡¡¡¡ÕâÊÇjspÒ³Ãæ´úÂ룺
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script src="./js/jquery-1.9.1.min.js" type="text/javascript"></script> <script src="./js/jquery.form.js" type="text/javascript"></script> <script src="./js/excelJs.js" type="text/javascript"></script> <style type="text/css"> .file { position: relative; display: inline-block; background: #D0EEFF; border: 1px solid #99D3F5; border-radius: 4px; /* padding: 4px 12px; */ overflow: hidden; color: #1E88C7; text-decoration: none; text-indent: 0; line-height: 20px; top:6px; } .file input { position: absolute; font-size: 100px; right: 0; top: 0; opacity: 0; } .file:hover { background: #AADFFD; border-color: #78C3F3; color: #004974; text-decoration: none; } .positionFile{ margin-left: 10px; margin-top: 30px; } .poConfirm{ margin-top: 40px; margin-left: 65px; } </style> </head> <body > <form> <input type="text" value="" readonly="readonly"> <a href="javascript:;">µã»÷ÉÏ´«Îļþ <input type="file" > </a> <br> <input type="button" value="È·¶¨"> <input type="button" value="È¡Ïû"> </form> </body> </html>
¡¡¡¡
¡¡