input type=file 格式化难题

来源:互联网 发布:快枪手软件下载 编辑:程序博客网 时间:2024/06/05 02:04

input type=file 附带按钮的样式几乎不被CSS所控制。这在其它按钮应用了特殊格式之后,这种按钮在界面上显的极不协调。就目前流行的几大浏览器来看,试图用样式表控制这种按钮的样式(或更改按钮上文字)都是不可能的。因而一些人采取隐藏input type=file而采用标准的按钮来代替它的方法。以下是一种比较简洁的实现,可工作在IE中。其中的关键是,IE为Form控件提供了click()方法,以便用程序指令替代人工点击。

<input type=file name=browse style="display: none;">
<input type=text name=file>
<input type=button
style="font-style:veranda; font-size:12px; font-weight:bold;text-transform:lowercase;color:white;background-color:#A2C382;height:22px;border-style:ridge;text-align:center;"
onClick="browse.disabled=false;browse.click();file.value=browse.value;browse.disabled=true"
value="Select a File...">

原文出处:http://www.webdeveloper.com/forum/archive/index.php/t-53084.html

更详细的研究:http://www.quirksmode.org/dom/inputfile.html

原创粉丝点击