根据HTML完成多图提交预览作用

自身近期写了1个网页页面多图提交的脚本制作,觉得挺好用的,细节就不必说了,立即贴编码了~

<head>
<style>
.pro_img{ margin-left:10px;margin-top:10px;width:300px;height: 300px;background-color: black; --border-radius:999em;  overflow:hidden;float:left; --margin:5% 35%;position: relative;}
.pro_img img{ position: absolute;left: 50%;top:50%;   transform: translate(⑸0%,⑸0%);width: 100%
}
.pro_img {position:relative}
.pro_img input{position: absolute;width: 100%;height: 100%;margin:0;opacity:0;z-index: 100;}
</style>
<script type="text/javascript" src="jquery.min.js"></script>
<script>
name_pic=1;
function t1(o){
//alert(name_pic);
    if(o==1 || name_pic!=1){
    var file="file"+o;
    var img="img"+o;
    var hid="hidden"+o;
    var aa="a"+o;
    }else{
    var file="file"+name_pic;
    var img="img"+name_pic;
    var hid="hidden"+name_pic;
    var aa="a"+name_pic;
    }
    var docObj = document.getElementById(file);
    var imgObjPreview = document.getElementById(img);
    var hidden=document.getElementById(hid);
    // alert(hidden);
    if (docObj.files && docObj.files[0]) {
        hidden.src=window.URL.createObjectURL(docObj.files[0]); //获得file文档的相对路径
        hidden.onload=function(){
            var width=hidden.width;
            var height=hidden.height;
            var a=document.getElementById(aa);
                if(width>height){
                imgObjPreview.style.cssText='width:100%';   //重新写过css款式
                }else{
                imgObjPreview.style.cssText='height:100%;width:auto;';                  
                }
        imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
        imgObjPreview.style.display = 'block';
        }
    }else{
        return false;
    }
    if(o==name_pic){
        var count=$('.pro_img').length;
        if(count<6){
        name_pic++;
    var pic_div="<a class='pro_img' id='a"+name_pic+"' ><input type='file' id='file"+name_pic+"'  accept='image/*' multiple='multiple' name='pic[]' onchange='t1("+name_pic+")'/><img src='upload.jpg' id='img"+name_pic+"'></a><img  id='hidden"+name_pic+"' style='display:none;'>";
    $('#upload').append(pic_div); 
    }       
}
}
</script>
</head>
<!-- multiple='multiple' -->
<form action="http://192.168.0.7/index.php/Home/Pic/upload" enctype="multipart/form-data" method="post">
<div id='upload'>
<a class='pro_img' id='a1' >
<input type='file' id='file1'  accept='image/*' multiple='multiple' name='pic[]' onchange='t1(1)'/>
<img src='upload.jpg' id='img1'></a>
<img  id='hidden1' style='display:none;'>
</div>
<input type='submit' value="提交" />
</form>

自身更换1些upload.png这张照片就可以做到自身的要求,假如说照片点一下没反映,别忘了添加jquery

以上所述是网编给大伙儿详细介绍的根据HTML完成多图提交预览作用,期待对大伙儿有一定的协助,假如大伙儿有任何疑惑请给我留言,网编会立即回应大伙儿的。在此也十分谢谢大伙儿对脚本制作之家网站的适用!