jquery.ocupload一键上传
2020-06-08 本文已影响0人
gaookey
普通上传
<body>
<form action="abc" method="post" enctype="multipart/form-data" target="myiframe">
<input type="file" name="filename"><br>
<input type="submit" value="上传">
</form>
<iframe name="myiframe" style="width: 10px;height: 20px"></iframe>
<%--<iframe name="myiframe" width="0" height="0"></iframe>--%>
</body>
jquery.ocupload
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.ocupload-1.1.2.js"></script>
<title>Title</title>
<script type="text/javascript">
$(function () {
$("#uploadbtn").upload({
action: 'abc',
name: 'filename',
params: {
'rand': Math.random()
},
onSelect: function (self, element) {//当选择好文件后触发,检查文件是否合法
this.autoSubmit = false;
var re = 通过文件后缀名规定文件类型的正则;
if (!re.test(this.filename())) {
alert("Only xxx file can be uploaded");
} else {
this.submit();
}
},
onSubmit: function (self, element) {
$('#uploadbtn').hide();
$('#ajax_update').parent().show();
},
onComplete: function (data, self, element) {
$('#ajax_update').parent().hide();
$('#uploadbtn').show();
try {
var ret = data;
if (ret.indexOf("exception") >= 0) {
alert('Upload file exception: ' + eval(data)[0].exception);
} else {
showSuccess('File is successfully Load.');
uploadSuccess(ret);
}
} catch (err) {
alert(data);
}
}
});
});
</script>
</head>
<body>
<input type="button" id="uploadbtn" value="一键上传">
</body>
</html>