javascript - 我想实现上传两张图片,结果上传第二张时第一张就不见了。
黄舟
黄舟 2017-04-10 15:51:14
[JavaScript讨论组]

代码如下:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript">
 $(function(){
     var num=0;
     
    $('#input').change(function(){
        num++;
        var mm=num*110;
        console.log(mm);
        console.log(num);
        var img="";
        var arr=[];
        var url=$('#input').val();
        arr.push(url);
        
        console.log(arr.length);
        while(arr.length>4){
            return -1;
        }
        for(var i=0;i<arr.length&&num<3;i++){
                var file=document.getElementById("input").files[i];
                var reader=new FileReader();
                reader.readAsDataURL(file);
                reader.onload=function(){
                    ss=reader.result;
                    img+='<img src="'+ss+'">'
                      //$('#box').html(img);
                      document.getElementById("box").innerHTML=img;
                     $('#box').css({'margin-top':'-99px','margin-left':+mm+'px','width':'500px','height':'200px','overflow':'hidden'});
        $('#box img').css({'width':'100px','height':'100px','float':'left'});  
                };
               
        }
       
    
    }); 
    
 });
</script>
<style type="text/css">

        input{position:relative;opacity:0;z-index:99;width:100px;height: 100px;}
        #img{position: absolute;top:10;left:10;}
</style>
</head>
<body>
<form name="form1" id="form1">

<input id="input"  type="file" multiple/>
<img id="img" src="Chrysanthemum.jpg"  width="100" height="100" style="float: left;">
<p id='box'>
        
</p>

</form>
</body>
</html>
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回复(1)
怪我咯

你上传两张图片那就用两个input啊

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号