JSP引用该JS
<script type="text/javascript" src="http://malsup.github.com/jquery.form.js"></script>
表单保存按钮 οnclick=save();
function save(){
var ipts = $('.resblockName'), repeat = '';
$(".resblockName").each(function () {
if (ipts.filter('[value="' + this.value + '"]').size()>1) {
repeat = this.value;
return false;
}
});
if (repeat !== ''){
alert('有重复名称,为:' + repeat + '!');
return false;
}
if(confirm("上传压缩包文件大,耗时长,需要您耐心等待,确定要上传吗?")){
//上传按钮置灰,新增按钮置灰
//$("#bsubmit").attr("disabled" , true).html("<i class=\"icon-spinner icon-spin\"></i> 正在提交中...").attr("onclick","");
$("#bsubmit").attr("disabled" , true).attr("onclick","");
$("#newBtn").attr("disabled" , true).attr("onclick","");
$(".uploadForm").each(function(index){//form-index
//判断是否有值
var resblockId=$(this).find(".resblockId").val();
var fileName=$(this).find(".tp").val();
if(fileName=='' || resblockId==''){
$(".upload-msg-span").eq(index).attr("style","color:red;").html("<i class=\"fa fa-times\"></i>名称及文件必选。");
return true ;
}
$(this).ajaxSubmit({
url:"<%=basePath%>picture/saveResblock720.do",
iframe: true,
enctype:'multipart/form-data',
success:function(data, statusText) {
var resultMsg="";
if(data!=null){
resultMsg=data.resultMsg;
if(data.resultStatus==200){
resultMsg="<i class=\"icon-ok\"></i>"+resultMsg;
$(".upload-msg-span").eq(index).attr("style","color:blue;").html(resultMsg);
}else{
resultMsg="<i class=\"fa fa-times\"></i>"+resultMsg;
$(".upload-msg-span").eq(index).html(resultMsg);
}
}
},error: function(arg1, arg2, ex) {
var resultMsg="<i class=\"fa fa-times\"></i>上传异常,请重试。";
$(".upload-msg-span").eq(index).html(resultMsg);
},
dataType: 'json'
});
});
// 文件上传结束后的 按钮修改
//$("#bsubmit").html("<i class=\"icon-ok\"></i>上传结束");
}
}
$(document).ready(function() {
var options = {
target: '#mydiv', // 需要刷新的区域
//beforeSubmit: showRequest, // 提交前调用的方法
//success: showResponse // 返回后笤俑的方法
// other available options:
//url: url // 提交的URL, 默认使用FORM ACTION
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // 是否清空form
//resetForm: true // 是否重置form
// $.ajax options can be used here too, for example:
//timeout: 3000
};
// 绑定FORM提交事件
$('#myForm').submit(function() {
$(this).ajaxSubmit(options);
// !!! Important !!!
// always return false to prevent standard browser submit and page navigation
return false;
});
});
转自: http://www.cnblogs.com/yqskj/archive/2013/06/05/3119479.html