估计很多人都对文件域那难看的样式无可奈何,对于一个讲究完美的web系统来说,这种界面是无法接受的。gmail的附件添加在ie浏览器中实现了样式自定义,让大伙兴奋了好一这,他使用的是文件域的click()方法,但客户端的安全限制非常苛刻,必须结合iframe才能实现,代码比较繁锁。我使用的是透明叠加法,即把文件域置于点击目标之上,并让其透明,这样用户看到的是自定义热区,点击的依然是浏览按钮,没有违反任何安全机制。同样地,这种方法也支持firefox。
*{font-size:12px;cursor:default}
.hand{cursor:hand;cursor:pointer}
@添加附件
file_create()
function file_create(){
$("bxatt2").innerhtml=""
}
function file_change(tx){
var sname,o
sname=tx.value.replace(/\\/g,"/").replace(/(.*\/)(.*)/,"$2")
o=document.createelement("nobr")
o.style.csstext="float:left;margin-right:6;padding-top:3;color:darkgreen"
o.innerhtml="□"+sname+""+unescape("×")+""
tx.style.display="none"
o.appendchild(tx)
$("bxattlist").insertbefore(o,$("bxatt"))
file_repos()
file_create()
}
function file_repos(){
$("bxattlist").appendchild($("bxatt"))
}
function $(obj){
return typeof(obj)=="object"?obj:document.getelementbyid(obj)
}
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]