美化 file input 框

18 篇文章 0 订阅

1. 浏览器端显示           

    


2. 示例下载(免积分)


          美化file input.zip


3. 代码


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>4</title>
    <script type="text/javascript" src="http://www.927car.com/js/jquery-1.11.1.js"></script>
<style>
* { margin: 0; padding: 0; }
input { border: none 0; }

.fileInputBox { width: 188px; overflow: hidden; position: relative;  margin: 100px auto; }
.fileInputBox * { float: left; }

.fileBtn { width: 52px; height: 22px; background: url("./images/browse_btn.jpg") no-repeat; font-family: arial; font-size: 12px; color: white; margin-left: 4px; }    
.fileDir { width: 130px; height: 20px; border: solid 1px #dedede; }

.fileInput { height: 22px; filter:alpha(opacity=00); -moz-opacity:0.0; -khtml-opacity: 0.0; opacity: 0.0; position: absolute; right: 0px; }

/*********** css hack ***********/
@-moz-document url-prefix() {
    .fileInput {
        left: 136px; 
    }
}
@media screen and (-webkit-min-device-pixel-ratio:0)    {
    .fileInput { 
        left: 136px; 
    }
}
/*********** css hack ***********/

</style>
<script>
jQuery(document).ready(function($) {
    var $fileInput = $(".fileInput");
    var $fileDir = $(".fileDir");
    var $fileBtn = $(".fileBtn");

    $fileInput.change(function(event) {
        $fileDir.attr('value', this.value);        
    });
});
</script>
</head>
<body>

    <div class="fileInputBox">
        
        <input class="fileInput" type="file"><!-- 被隐藏 -->

        <input class="fileDir" type="text"><!-- 显示文件路径 -->
        <input class="fileBtn" type="button" value="浏览"><!-- 替换后的浏览按钮 -->

    </div>

</body>
</html>


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值