zoukankan      html  css  js  c++  java
  • 上传头像

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4     <title>test</title>
     5 </head>
     6 <body>
     7  
     8 <div>
     9     头像:
    10     <label for="file"><img style=" 20px;" src="https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2790581511,3561251597&fm=58"></label>
    11     <input type="file" name="" id="file" style="display: none;">
    12 </div>
    13  
    14 <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    15 <script>
    16     // 找到头像的input标签绑定事件
    17     $("#file").on("change", function(){
    18         // 创建一个读取文件的对象
    19         var fileReader = new FileReader();
    20         // 读取选择的文件
    21         fileReader.readAsDataURL(this.files[0]);
    22         // 等待文件读取完毕
    23         fileReader.onload = function(){
    24             // 更改img的src属性
    25             $("img").attr("src", fileReader.result);
    26         };
    27     })
    28 </script>
    29 </body>
    30 </html>
  • 相关阅读:
    网络七层模型
    border-radius 50% 和100%
    数据绑定
    前端一些基础的重要的知识2
    用 ul 和 li 模拟select控件
    两列布局
    盒子的水平垂直居中几种方法
    TCP时间戳
    帧聚合
    skb buff数据结构
  • 原文地址:https://www.cnblogs.com/changwoo/p/9568431.html
Copyright © 2011-2022 走看看