Input file 文本框美化

时间:2023-03-09 08:46:16
Input file 文本框美化

HTML原生的input file 上传按钮有多(无)不(力)漂(吐)亮(槽)我就不多说了。大家几乎在项目中都会有遇到图片、等文件需要上传的地方,好看的文件上传按钮会使人身心愉悦(我瞎说的)。好了不多废话了,今天就教大家使用Jquery配合CSS写出一个美化文件上传按钮效果的教程。

效果如下图:

Input file 文本框美化

直接上完整代码:

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HTML Input file美化</title>
<style type="text/css">
a{text-decoration:none;}
a[class="button-selectimg"],input[type='submit']{color:#00A2D4;padding:4px 6px;border:1px dashed #00A2D4;border-radius:2px;}
.input-file{margin:200px 300px;}
input[id="avatval"]{padding:3px 6px;padding-left:10px;border:1px solid #E7EAEC;width:230px;height:25px;line-height:25px;border-left:3px solid #3FB7EB;background:#FAFAFB;border-radius:2px;}
input[type='file']{border:0px;display:none;}
</style>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$(function(){
$("#avatsel").click(function(){
$("input[type='file']").trigger('click');
});
$("#avatval").click(function(){
$("input[type='file']").trigger('click');
});
$("input[type='file']").change(function(){
$("#avatval").val($(this).val());
});
});
</script>
</head>
<body>
<div class="input-file">
<form action="input.html" method="get" enctype="multipart/form-data">
<input type="text" id="avatval" placeholder="请选择文件···" readonly="readonly" style="vertical-align: middle;"/>
<input type="file" name="avatar" id="avatar"/>
<a href="javascript:void(0);" class="button-selectimg" id="avatsel">选择文件</a>
<input type="submit" name="" id="" value="提交" />
</form>
</div>
</body>
</html>

表单提交后的效果,如下图:

Input file 文本框美化

博主留言:请尊重他人劳动成果,转载请注明文章出处。

当前文章链接:http://www.cnblogs.com/hollow/p/6420813.html