- 本文出自svtter.github.io
上传文件type=file
真心丑,所以采用方法解决一下。
中心思想是隐藏input
,然后利用css定位,使其仍然可以被点击(有点欺骗的性质)
text需要禁止点击(使用diabled='disabled'
)
源代码
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>定义input type="file" 的样式</title> <style type="text/css"> body{ font-size:14px;} input{ vertical-align:middle; margin:; padding:} .file-box{ position:relative;width:340px} .txt{ height:22px; border:1px solid #cdcdcd; width:180px;} .btn{ background-color:#FFF; border:1px solid #CDCDCD;height:24px; width:70px;} .file{ position:absolute; top:; right:85px; height:24px; filter:alpha(opacity:);opacity: ;width:70px } </style> </head> <body> <div class="file-box"> <form action="" method="post" enctype="multipart/form-data"> <input type='text' name='textfield' id='textfield' class='txt' disabled='disabled'/> <input type='button' class='btn' value='浏览...' /> <input type="file" name="fileField" class="file" id="fileField" size="28" onchange="document.getElementById('textfield').value=this.value" /> <input type="submit" name="submit" class="btn" value="上传" /> </form> </div> </body> </html>