自定义文件上传方式下面的代码在ie中没问题,而在firefox中怎么获取上传的文件名称失败呢?忘高手指点。 <html> <script type="text/javascript"> function upload(){ var div=document.getElementById("uploaderContainer");
var uploader=document.getElementById("uploaderContainer").firstChild; //alert(uploader); var fileName=(uploader==null)?"":uploader.value; //alert(fileName); if(fileName.lenght==0){ setTimeout("updateFileName()",100);
2、用 display: none
/*file容器样式*/
a.files {
width:90px;
height:30px;
overflow:hidden;
display:block;
border:1px solid #BEBEBE;
text-decoration:none;
}
a.files:hover {
background-color:#FFFFEE;
background-position:0 -30px;
}
/*file设为透明,并覆盖整个触发面*/
a.files input {
margin-left:-350px;
font-size:30px;
cursor:pointer;
filter:alpha(opacity=0);
opacity:0;
}
</style>
<a href="javascript:void(0);" class="files">选择文件...<input type="file"/></a>
display:none;不会影响功能。如果你想按钮有被点击效果,只要出发对应按钮的click事件即可。我好奇你那个span怎样获取最新上传的文件名
<html>
<script type="text/javascript">
function upload(){
var div=document.getElementById("uploaderContainer");
div.innerHTML="<input type='file' />";
div.firstChild.click();
setTimeout("updateFileName()",100);
}
function updateFileName(){
var uploader=document.getElementById("uploaderContainer").firstChild;
//alert(uploader);
var fileName=(uploader==null)?"":uploader.value;
//alert(fileName);
if(fileName.lenght==0){
setTimeout("updateFileName()",100);
}else{
document.getElementById("fileName").value=fileName.replace(/.*\\/,"");
}
}
function showFileName(){
alert(document.getElementById("test").value);
}
</script>
<style type="text/css"> #uploaderContainer{
display:none;
}
</style><body>
<div id="uploaderContainer"></div>
<input type="text" id="fileName" />
<input type="button" onclick="upload()" value="浏览" /></body>
</html>
假设如果 你要在 file按钮提交后执行 button事件可以用 $("button").trigger("click");
假设如果 你不需要执行button的click, 那么 你在file提交后 用CSS控制假button的样式就行,
至于你的动画效果不知道是什么样的,如果是慢慢消失或者 隐藏 jquery 也有封闭的效果,如果只是做点击后的一个效果展示 就用CSS就好了。
2.设置样式opacity,z-index添加按钮置于其上
/*file容器样式*/
a.files {
width:90px;
height:30px;
overflow:hidden;
display:block;
border:1px solid #BEBEBE;
text-decoration:none;
}
a.files:hover {
background-color:#FFFFEE;
background-position:0 -30px;
}
/*file设为透明,并覆盖整个触发面*/
a.files input {
margin-left:-350px;
font-size:30px;
cursor:pointer;
filter:alpha(opacity=0);
opacity:0;
}
</style>
<a href="javascript:void(0);" class="files">选择文件...<input type="file"/></a>按照你的方法做的,效果如此,点击框里的下方空白处才能弹出浏览框,别的地方无用,