• input type="file"在各个浏览器下的默认样式,以及修改自定义样式


    一、<input type="file"/>在各个浏览器中的默认样式:

    系统浏览器样式效果点击效果
    mac google mac-google-inputfile 点击按钮和输入框都可以打开文件夹
    mac firfox 点击按钮和输入框都可以打开文件夹
    mac safari 点击按钮和输入框都可以打开文件夹
    win10 google 点击按钮和输入框都可以打开文件夹
    win10 firefox 点击按钮和输入框都可以打开文件夹
    win10 edge 点击按钮和输入框都可以打开文件夹
    win10 ie11 点击按钮和输入框都可以打开文件夹
    win10 ie11仿真ie109875 点击按钮可以打开文件夹,输入框不可以打开文件夹

     二、修改成自己的样式

    目标样式如下:

    当上传文件后,会在右侧显示文件名

     点击,在新窗口打开演示版:www.jusctice.cn/u1 (基础演示用,没有做更多判断容错处理,所以别传太大的文件)

    具体代码:

    -- css --

            .inputFileWrapper label{
                display: block;
                float: left;
                position: relative;
            }
            .inputFileWrapper input[type="file"]{
                position: absolute;
                width: 1px;
                height: 1px;
                clip:rect(0,0,0,0);
            }
            .inputFileWrapper .custorm-style{
                display: block;
                width: 390px;
                height: 50px;
            }
            .inputFileWrapper .custorm-style .left-button{
                width: 80px;
                line-height: 50px;
                background: #008ac7;
                color: #fff;
                display: block;
                text-align: center;
                float: left;
            }
            .inputFileWrapper .custorm-style .right-text{
                width: 300px;
                height: 40px;
                line-height: 50px;
                display: block;
                float: right;
                padding: 4px;
                border: 1px solid #008ac7;
                overflow: hidden;
                -ms-text-overflow: ellipsis;
                text-overflow: ellipsis;
                white-space: nowrap;
            }

     --html--

    1 <div class="inputFileWrapper">
    2     <label for="inputFile">
    3         <input type="file" id="inputFile"/>
    4         <span class="custorm-style">
    5             <span class="left-button">上传头像</span>
    6             <span class="right-text" id="rightText"></span>
    7         </span>
    8     </label>
    9 </div>

    --js--

    1 <script src="js/jquery-1.11.2-min.js"></script>
    2 <script>
    3     var fileBtn = $("input[type=file]");
    4     fileBtn.on("change", function(){
    5         var index = $(this).val().lastIndexOf("\");
    6         var sFileName = $(this).val().substr((index+1));
    7         $("#rightText").html(sFileName);
    8     });
    9 </script>
  • 相关阅读:
    VC++下封装ADO类以及使用方法
    MFC浅析(7) CWnd类虚函数的调用时机、缺省实现
    JavaScript原生数组函数
    C#4.0泛型的协变,逆变深入剖析
    《这就是搜索引擎:核心技术详解》总结
    栈和队列
    JS菜单条智能定位效果
    实现模型工厂,依赖注入以及格式配置
    Intellij IDEA 快捷键整理
    printf code
  • 原文地址:https://www.cnblogs.com/hamsterPP/p/5804512.html
Copyright © 2020-2023  润新知