JS 上传文件 页面先展示文件名字、图片小技巧

一、文件名字

 

1、jsp
                            <c:if test="${pd.REMARK != '' && pd.REMARK !=null}">
                            <input type="file" name="uptohtml" id="uptohtml" style="display: none;"/>
                            <a href="javascript:void(0);" οnclick="upclick();" style='color:black;text-decoration: none'>上传文档选择(doc、docx、xls、xlsx)</a>
                            <span id="fileName" ></span>&nbsp;&nbsp;
                            <a href="javascript:void(0);" οnclick="showFile('${pd.REMARK}');" style='text-decoration: none;' id="showFile">查看文档</a>
                            </c:if>

 

2、Js文件

 function upclick(){
         $('#uptohtml').click();
       } 

 

 

 $(function() {
       $("#uptohtml").change(function(){
                    //获取FileUpload对象
                    var x = document.getElementById("uptohtml").files;
                    //把获得的文件名放入text里面显示
                    $("#fileName").text(x[0].name);
                    $("#showFile").hide();
                });
       });

 

 

二、图片

1、jsp

<div class="ImgDiv">
                            <input type="file" name="NOTICE_IMAGE" id="NOTICE_IMAGE" style="display: none;"/>

<c:if test="${pd.NOTICE_IMAGE != '' && pd.NOTICE_IMAGE !=null}">                                                        
                            <a href="javascript:void(0);" οnclick="Imgclick();" style='color:black;text-decoration: none;'>更改图片</a>
                            <img src="uploadFiles/file/${pd.NOTICE_IMAGE}" class="Imgcss"/>      
</c:if>

 </div>

 

 

2、JS文件

function Imgclick(){
         $('#NOTICE_IMAGE').click();
       }
       
       $(function() {
       $("#NOTICE_IMAGE").change(function(){
        var file= document.getElementById("NOTICE_IMAGE").files[0];        //获取FileUpload对象


        var reader = new FileReader();        //创建读取文件的对象


        reader.οnlοad=function(e) {
        imgFile = e.target.result;
        $(".Imgcss").attr('src', imgFile);
        };


       reader.readAsDataURL(file); //正式读取文件        

    
                });                             
       });
       
三、 鼠标经过图标放大

       1、css

.ImgDiv{  // div大小
  width:100%;
  border: #000 solid 0px;
}  
  
.Imgcss{  //最初大小
  width:20px;
  height:20px;
 }
   
.ImgDiv img{
  cursor: pointer;
  transition: all 0.6s; //放大经过时间
}

.ImgDiv img:hover{
  transform: scale(8.0); //放大倍数
}

 

2、html

第二标红字体

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值