一串JS怎么合并成一个啊
<scripttype="text/javascript">$(document).ready(function(e){varprogress1=$(".progress...
<script type="text/javascript">
$(document).ready(function(e) {
var progress1 = $(".progress1");
var progress_bar1 = $(".progress-bar1");
var percent1 = $('.percent1');
$("#uploadphoto1").change(function(){
$("#myupload1").ajaxSubmit({
dataType: 'json', //数据格式为json
beforeSend: function() { //开始上传
progress1.show();
var percentVal1 = '0%';
progress_bar1.width(percentVal1);
percent1.html(percentVal1);
},
uploadProgress: function(event, position, total, percentComplete1) {
var percentVal1 = percentComplete1 + '%'; //获得进度
progress_bar1.width(percentVal1); //上传进度条宽度变宽
percent1.html(percentVal1); //显示上传进度百分比
},
success: function(data) {
if(data.status == 1){
var add1 = document.getElementById('add1');
add1.style.display = "none";
var delet1= document.getElementById('delet1');
delet1.style.display = "block";
var src1 = data.url;
var attstr1= '<img id="card1" src="'+src1+'" height="330px" />';
$(".imglist1").append(attstr1);
$(".res1").html("上传图片"+data.name+"成功,图片大小:"+data.size+"K,文件地址:"+data.url);
}else{
$(".res1").html(data.content);
}
progress1.hide();
},
error:function(xhr){ //上传失败
alert("上传失败");
progress1.hide();
}
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function(e) {
var progress2 = $(".progress2");
var progress_bar2 = $(".progress-bar2");
var percent2 = $('.percent2');
$("#uploadphoto2").change(function(){
$("#myupload2").ajaxSubmit({
dataType: 'json', //数据格式为json
beforeSend: function() { //开始上传
progress2.show();
var percentVal2 = '0%';
progress_bar2.width(percentVal2);
percent2.html(percentVal2);
},
uploadProgress: function(event, position, total, percentComplete2) {
var percentVal2 = percentComplete2 + '%'; //获得进度
progress_bar2.width(percentVal2); //上传进度条宽度变宽
percent2.html(percentVal2); //显示上传进度百分比
},
success: function(data) {
if(data.status == 1){
var add2 = document.getElementById('add2');
add2.style.display = "none";
var delet2 = document.getElementById('delet2');
delet2.style.display = "block";
var src2 = data.url;
var attstr2= '<img id="card2" src="'+src2+'" height="330px" />';
$(".imglist2").append(attstr2);
$(".res2").html("上传图片"+data.name+"成功,图片大小:"+data.size+"K,文件地址:"+data.url);
}else{
$(".res2").html(data.content);
}
progress2.hide();
},
error:function(xhr){ //上传失败
alert("上传失败");
progress2.hide();
}
});
});
});
</script> 展开
$(document).ready(function(e) {
var progress1 = $(".progress1");
var progress_bar1 = $(".progress-bar1");
var percent1 = $('.percent1');
$("#uploadphoto1").change(function(){
$("#myupload1").ajaxSubmit({
dataType: 'json', //数据格式为json
beforeSend: function() { //开始上传
progress1.show();
var percentVal1 = '0%';
progress_bar1.width(percentVal1);
percent1.html(percentVal1);
},
uploadProgress: function(event, position, total, percentComplete1) {
var percentVal1 = percentComplete1 + '%'; //获得进度
progress_bar1.width(percentVal1); //上传进度条宽度变宽
percent1.html(percentVal1); //显示上传进度百分比
},
success: function(data) {
if(data.status == 1){
var add1 = document.getElementById('add1');
add1.style.display = "none";
var delet1= document.getElementById('delet1');
delet1.style.display = "block";
var src1 = data.url;
var attstr1= '<img id="card1" src="'+src1+'" height="330px" />';
$(".imglist1").append(attstr1);
$(".res1").html("上传图片"+data.name+"成功,图片大小:"+data.size+"K,文件地址:"+data.url);
}else{
$(".res1").html(data.content);
}
progress1.hide();
},
error:function(xhr){ //上传失败
alert("上传失败");
progress1.hide();
}
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function(e) {
var progress2 = $(".progress2");
var progress_bar2 = $(".progress-bar2");
var percent2 = $('.percent2');
$("#uploadphoto2").change(function(){
$("#myupload2").ajaxSubmit({
dataType: 'json', //数据格式为json
beforeSend: function() { //开始上传
progress2.show();
var percentVal2 = '0%';
progress_bar2.width(percentVal2);
percent2.html(percentVal2);
},
uploadProgress: function(event, position, total, percentComplete2) {
var percentVal2 = percentComplete2 + '%'; //获得进度
progress_bar2.width(percentVal2); //上传进度条宽度变宽
percent2.html(percentVal2); //显示上传进度百分比
},
success: function(data) {
if(data.status == 1){
var add2 = document.getElementById('add2');
add2.style.display = "none";
var delet2 = document.getElementById('delet2');
delet2.style.display = "block";
var src2 = data.url;
var attstr2= '<img id="card2" src="'+src2+'" height="330px" />';
$(".imglist2").append(attstr2);
$(".res2").html("上传图片"+data.name+"成功,图片大小:"+data.size+"K,文件地址:"+data.url);
}else{
$(".res2").html(data.content);
}
progress2.hide();
},
error:function(xhr){ //上传失败
alert("上传失败");
progress2.hide();
}
});
});
});
</script> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询