jquery 预览并自增 上传图片


核心代码

  <script src="{:CUSTOM_TEMPLATE_PATH}Index/index/js/jquery-1.8.3.min.js"></script>
    <!-- 包含了所有编译插件 -->
    <script src="{:CUSTOM_TEMPLATE_PATH}Index/index/js/bootstrap.min.js"></script>
<script type="text/javascript">
window.οnlοad=function(){
//alert("加载完毕");
document.getElementById("pic2").style.visibility="hidden";
document.getElementById("pic3").style.visibility="hidden";
//document.getElementById("EleId").style.visibility="visible"; 
}


</script>
 <script type="text/javascript">  
        $(function(){  
            $("#pic").change(function(){  
				document.getElementById("pic2").style.visibility='visible';
                if($.browser.msie){    
                    $("#img0").attr("src",$(this).val())  
                    $("#info").text("当前选择的文件:"+$(this).val())  
                }else{  
                    $("#info").text("当前选择的文件:"+$(this).val())  
                    var objUrl=getObjectURL(this.files[0]);  
                    console.log("objUrl="+objUrl);  
                    if(objUrl){  
                        $("#img0").attr("src",objUrl);  
                    }  
                }  
            })  
            //建立一個可存取到該file的url  
            function getObjectURL(file) {  
                var url = null ;   
                if (window.createObjectURL!=undefined) {  
                    url = window.createObjectURL(file) ;  
                } else if (window.URL!=undefined) {   
                    url = window.URL.createObjectURL(file) ;  
                } else if (window.webkitURL!=undefined) {   
                    url = window.webkitURL.createObjectURL(file) ;  
                }  
                return url ;  
            }  
        })  

		$(function(){  
            $("#pic2").change(function(){  
				document.getElementById("pic3").style.visibility='visible';
                if($.browser.msie){  
                    $("#img2").attr("src",$(this).val())  
                    $("#info2").text("当前选择的文件:"+$(this).val())  
                }else{  
                    $("#info2").text("当前选择的文件:"+$(this).val())  
                    var objUrl=getObjectURL(this.files[0]);  
                    console.log("objUrl="+objUrl);  
                    if(objUrl){  
                        $("#img2").attr("src",objUrl);  
                    }  
                }  
            })  
            //建立一個可存取到該file的url  
            function getObjectURL(file) {  
                var url = null ;   
                if (window.createObjectURL!=undefined) {  
                    url = window.createObjectURL(file) ;  
                } else if (window.URL!=undefined) {   
                    url = window.URL.createObjectURL(file) ;  
                } else if (window.webkitURL!=undefined) {   
                    url = window.webkitURL.createObjectURL(file) ;  
                }  
                return url ;  
            }  
        })  

		$(function(){  
            $("#pic3").change(function(){  
                if($.browser.msie){  
                    $("#img3").attr("src",$(this).val())  
                    $("#info3").text("当前选择的文件:"+$(this).val())  
                }else{  
                    $("#info3").text("当前选择的文件:"+$(this).val())  
                    var objUrl=getObjectURL(this.files[0]);  
                    console.log("objUrl="+objUrl);  
                    if(objUrl){  
                        $("#img3").attr("src",objUrl);  
                    }  
                }  
            })  
            //建立一個可存取到該file的url  
            function getObjectURL(file) {  
                var url = null ;   
                if (window.createObjectURL!=undefined) {  
                    url = window.createObjectURL(file) ;  
                } else if (window.URL!=undefined) {   
                    url = window.URL.createObjectURL(file) ;  
                } else if (window.webkitURL!=undefined) {   
                    url = window.webkitURL.createObjectURL(file) ;  
                }  
                return url ;  
            }  
        })  
    </script>  
</head>

body

<div class="addto_ingput" style="padding-bottom:10px">
           <div class="addto_ingput_left pull-left">
               <label class="text-right">晒单 :</label>
           </div>
           <div class="addto_ingput_right pull-left">


       <div class="carousel-inner pull-left" style="width:20.25%; margin-right:4%; margin-top:4%">
	  <div class="item active">
          <input type="file" name="thesun_img[]" id="pic" class="file0" />        
          <span id="info"></span>  
          <img src="" alt="" id="img0" width="100" />  
	    </div>
        </div>

	<div class="carousel-inner pull-left" style="width:20.25%; margin-right:4%; margin-top:4%">
	   <div class="item active">
		  <input type="file" name="thesun_img[]" id="pic2" class="file0"/>        
         <span id="info2" style="margin-left:10px;"></span>  
        <img src="" alt="" id="img2" width="150" /> 
	   </div>
	</div>

	<div class="carousel-inner pull-left" style="width:20.25%; margin-right:4%; margin-top:4%">
	   <div class="item active">
		  <input type="file" name="thesun_img[]" id="pic3" class="file0"/>        
          <span id="info3" style="margin-left:10px;"></span>  
        <img src="" alt="" id="img3" width="180" />  
	   </div>
	</div>
		

		  <script type="text/javascript">


		$('#submit').click(function(){
			//alert('111111');
			$('#form').submit();
			
		});

		
	</script>

 	<div class="fbpl_btn">
	<input type="hidden" name="shopid" value="{$shopinfo.id}" >
	
		
	   </div>
	   </div>
	    <div class="clearfix"></div>
        <button id="submit" type="submit"  class="btn btn-primary btn-lg btn-block " style="background-color:#ea4c88; border-radius:15px; border:0; margin-top:15px">
      			发表评价
   		</button>


=============================================================================

图片替换上传 按钮(美观一些)   用图片盖住input上传文件控件。

例:

<style type="text/css">

    .fileInputContainer{
        height:256px;
        background:url(http://images.cnblogs.com/cnblogs_com/dreamback/437546/o_ff6.png);
        position:relative;
        width: 256px;
    }
    .fileInput{
        height:256px;
        font-size: 300px;
        position:absolute;
        right:0;
        top:0;
        opacity: 0;
        filter:alpha(opacity=0);
        cursor:pointer;
    }

</style>
<div class="fileInputContainer">
    <input class="fileInput" type="file" name="" id="" />
</div>

例:完整

<script src="{:CUSTOM_TEMPLATE_PATH}Index/index/js/jquery-1.8.3.min.js"></script>
    <!-- 包含了所有编译插件 -->
    <script src="{:CUSTOM_TEMPLATE_PATH}Index/index/js/bootstrap.min.js"></script>
<script type="text/javascript">
window.οnlοad=function(){
//alert("加载完毕");
document.getElementById("pic2").style.visibility="hidden";
document.getElementById("pic3").style.visibility="hidden";
document.getElementById("img2").style.visibility="hidden";
document.getElementById("img3").style.visibility="hidden";
//document.getElementById("EleId").style.visibility="visible"; 
}
</script>
<style type="text/css">

    .fileInputContainer{
       height:256px;
        //background:url(http://images.cnblogs.com/cnblogs_com/dreamback/437546/o_ff6.png);
        position:relative;
        width: 200px;
    }
    .fileInput{
        height:256px;
        font-size: 300px;
        position:absolute;
        right:0;
        top:0;
        opacity: 0;
        filter:alpha(opacity=0);
        cursor:pointer;
    }

</style>

 <script type="text/javascript">  
        $(function(){  
            $("#pic").change(function(){  
				document.getElementById("pic2").style.visibility='visible';
				document.getElementById("img2").style.visibility="visible";
                if($.browser.msie){    
                    $("#img0").attr("src",$(this).val())  
                   // $("#info").text("当前选择的文件:"+$(this).val())  
                }else{  
                   // $("#info").text("当前选择的文件:"+$(this).val())  
                    var objUrl=getObjectURL(this.files[0]);  
                    console.log("objUrl="+objUrl);  
                    if(objUrl){  
                        $("#img0").attr("src",objUrl);  
                    }  
                }  
            })  
            //建立一個可存取到該file的url  
            function getObjectURL(file) {  
                var url = null ;   
                if (window.createObjectURL!=undefined) {  
                    url = window.createObjectURL(file) ;  
                } else if (window.URL!=undefined) {   
                    url = window.URL.createObjectURL(file) ;  
                } else if (window.webkitURL!=undefined) {   
                    url = window.webkitURL.createObjectURL(file) ;  
                }  
                return url ;  
            }  
        })  

		$(function(){  
            $("#pic2").change(function(){  
				document.getElementById("pic3").style.visibility='visible';
				document.getElementById("img3").style.visibility="visible";
                if($.browser.msie){  
                    $("#img2").attr("src",$(this).val())  
                    //$("#info2").text("当前选择的文件:"+$(this).val())  
                }else{  
                   // $("#info2").text("当前选择的文件:"+$(this).val())  
                    var objUrl=getObjectURL(this.files[0]);  
                    console.log("objUrl="+objUrl);  
                    if(objUrl){  
                        $("#img2").attr("src",objUrl);  
                    }  
                }  
            })  
            //建立一個可存取到該file的url  
            function getObjectURL(file) {  
                var url = null ;   
                if (window.createObjectURL!=undefined) {  
                    url = window.createObjectURL(file) ;  
                } else if (window.URL!=undefined) {   
                    url = window.URL.createObjectURL(file) ;  
                } else if (window.webkitURL!=undefined) {   
                    url = window.webkitURL.createObjectURL(file) ;  
                }  
                return url ;  
            }  
        })  

		$(function(){  
            $("#pic3").change(function(){  
                if($.browser.msie){  
                    $("#img3").attr("src",$(this).val())  
                   // $("#info3").text("当前选择的文件:"+$(this).val())  
                }else{  
                   // $("#info3").text("当前选择的文件:"+$(this).val())  
                    var objUrl=getObjectURL(this.files[0]);  
                    console.log("objUrl="+objUrl);  
                    if(objUrl){  
                        $("#img3").attr("src",objUrl);  
                    }  
                }  
            })  
            //建立一個可存取到該file的url  
            function getObjectURL(file) {  
                var url = null ;   
                if (window.createObjectURL!=undefined) {  
                    url = window.createObjectURL(file) ;  
                } else if (window.URL!=undefined) {   
                    url = window.URL.createObjectURL(file) ;  
                } else if (window.webkitURL!=undefined) {   
                    url = window.webkitURL.createObjectURL(file) ;  
                }  
                return url ;  
            }  
        })  
    </script>  
</head>

body

 <div class="addto_ingput" style="padding-bottom:10px">
           <div class="addto_ingput_left pull-left">
               <label class="text-right">晒单 :</label>
           </div>
           <div class="addto_ingput_right pull-left">

	<div class="carousel-inner pull-left" style="width:20.25%; margin-right:4%; margin-top:4%">
	  <div class="item active fileInputContainer">
        <input type="file" name="thesun_img[]" id="pic" class="file0 fileInput" />        
         <span id="info"></span>  
        <a><img src="{:CUSTOM_TEMPLATE_PATH}Index/index/img/tj_img.png" alt="" id="img0" width="160"  />  </a>
	   </div>
    </div>

	<div class="carousel-inner pull-left" style="width:20.25%; margin-right:4%; margin-top:1%">
	   <div class="item active fileInputContainer">
		  <input type="file" name="thesun_img[]" id="pic2" class="file0 fileInput"/>        
         <span id="info2" style="margin-left:10px;"></span>  
        <img src="{:CUSTOM_TEMPLATE_PATH}Index/index/img/tj_img.png" alt="" id="img2" width="160" /> 
	   </div>
	</div>

	<div class="carousel-inner pull-left" style="width:20.25%; margin-right:4%; margin-top:1%">
	   <div class="item active fileInputContainer">
		  <input type="file" name="thesun_img[]" id="pic3" class="file0 fileInput"/>        
          <span id="info3" style="margin-left:10px;"></span>  
        <img src="{:CUSTOM_TEMPLATE_PATH}Index/index/img/tj_img.png" alt="" id="img3" width="160" />  
	   </div>
	</div>
		

		  <script type="text/javascript">


		$('#submit').click(function(){
			//alert('111111');
			$('#form').submit();
			
		});

		
	</script>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蜗牛慢慢向上爬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值