<input type="file"/>的问题 如何实现点击一张图片实现<input type="file"/>的功能? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script type="text/javascript"> function openFile() { document.getElementById("file1").click(); }</script><input type="file" id="file1"/><input type="button" value="open file" onclick="openFile()"/>把上面的Button换成图片就可以了。 4楼的方法也可以。 ----另外有一种方法是用css来实现。原理就是: 将input file的z-index设得比图片高,这样,它将覆盖在这张图片上。 然后,通过css将图片定位到这个input file 的正下方。 这样就能实现点击图片,相当于点击input file的效果。 最后,将input file的透明度设为0即可。如下代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <meta name="generator" content="editplus" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <style type="text/css"> #upload{position:absolute;overflow:hidden;} #file{position:absolute;z-index:100;opacity:0;filter:alpha(opacity=0);font-size:60px;margin-top:-5px;margin-left:-700px;cursor:pointer;} </style> </head> <body> <span id="upload"> <input type="file" id="file" name="file" /> <a href="javascript:void(0)">上传图片</a> </span> </body></html> 5楼介绍的很详细,看看网易,开心网的实现方式,你就明白了!隐藏了input,将图片盖在它身上。障眼法! 使用滤镜兼容性不是很好,如果要隐藏file控件的话,设置啊的display为none,然后使用js自定义需要上传的文件的显示,这个在多文件上传的时候会用到。 JQuery append方法求助? 保存时出错,求大神知道 求一个通用的clearboth层 求javascript里限制 text 框里的输入 iframe自适应调整高度问题 在线等 急! 如何获得一个下拉列表框里已经被选中的值? 判断并提示设置首页的问题 请教一个隐藏IE 工具条的代码! 如何获得页面数据? 关于删除一条记录的问题! 怎么加了分号就会出问题.............. 关于获取有空格的值的问题
<script type="text/javascript">
function openFile() {
document.getElementById("file1").click();
}
</script>
<input type="file" id="file1"/>
<input type="button" value="open file" onclick="openFile()"/>把上面的Button换成图片就可以了。
----
另外有一种方法是用css来实现。
原理就是:
将input file的z-index设得比图片高,这样,它将覆盖在这张图片上。
然后,通过css将图片定位到这个input file 的正下方。
这样就能实现点击图片,相当于点击input file的效果。
最后,将input file的透明度设为0即可。
如下代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
#upload{position:absolute;overflow:hidden;}
#file{position:absolute;z-index:100;opacity:0;filter:alpha(opacity=0);font-size:60px;margin-top:-5px;margin-left:-700px;cursor:pointer;}
</style>
</head> <body> <span id="upload">
<input type="file" id="file" name="file" />
<a href="javascript:void(0)">上传图片</a>
</span>
</body>
</html>