zoukankan      html  css  js  c++  java
  • 自定义上传按钮美化上传按钮input type=file (完整)

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>美化上传按钮</title>
     6     <style>
     7         .a-upload {
     8             padding: 4px 10px;
     9             height: 20px;
    10             line-height: 20px;
    11             position: relative;
    12             cursor: pointer;
    13             color: #888;
    14             background: #fafafa;
    15             border: 1px solid #ddd;
    16             border-radius: 4px;
    17             overflow: hidden;
    18             text-decoration: none;
    19             display: inline-block;
    20             *display: inline;
    21             *zoom: 1
    22         }
    23         .a-upload  input {
    24             position: absolute;
    25             font-size: 100px;
    26             right: 0;
    27             top: 0;
    28             opacity: 0;
    29             filter: alpha(opacity=0);
    30             cursor: pointer
    31         }
    32 
    33         .a-upload:hover {
    34             color: #444;
    35             background: #eee;
    36             border-color: #ccc;
    37             text-decoration: none
    38         }
    39     </style>
    40 </head>
    41 <body>
    42 <a href="javascript:;" class="a-upload">
    43     <input type="file" name="" id="">点击这里上传文件
    44 </a>
    45 <div id="fileerrorTip"></div>
    46 <div id="showFileName"></div>
    47 <script src=jquery.min.js></script>
    48 <script>
    49     //显示文件名
    50     $(".a-upload").on("change","input[type='file']",function(){
    51         var filePath=$(this).val();
    52         if(filePath.indexOf("jpg")!=-1 || filePath.indexOf("png")!=-1){
    53             $("#fileerrorTip").html("").hide();
    54             var arr=filePath.split('\');
    55             var fileName=arr[arr.length-1];
    56             console.log(fileName);
    57             $("#showFileName").html(fileName);
    58         }else{
    59             $("#showFileName").html("");
    60             $("#fileerrorTip").html("您未上传文件,或者您上传文件类型有误!").show();
    61             return false;
    62         }
    63     })
    64 </script>
    65 </body>
    66 </html>
  • 相关阅读:
    关键路径的计算
    JSF简单介绍
    介绍:一款Mathematica的替代开源软件Mathetics
    素材链接
    JSP动作--JSP有三种凝视方式
    【InversionCount 逆序对数 + MergeSort】
    全响应跨设备的Zoomla!逐浪CMS2 x2.0正式公布
    DirectSound的应用
    “海归”首选北上广 薪资期望不太高-有感
    Servlet登陆功能的实现
  • 原文地址:https://www.cnblogs.com/wu-hou/p/6377135.html
Copyright © 2011-2022 走看看