用javascript打开文本选择对话框 怎么样只点击一个图标,立刻打开一个文本选择对话框,就像input的file 那样?要求用javascript,另外这个方法还要同时适应 firefox和ie,而且客户端不需要注册任何插件或者com组件请各位高手帮忙!感激不尽 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不知道你打开以后要如何处理了,不过可以让系统点击一个隐藏的file表单来实现.<html> <head> <script type="text/javascript"> function openFileSelect(){ var obj = document.getElementById('test'); obj.click();}</script> </head> <body> <img src='xxx.gif' onclick='openFileSelect();'/><input type='file' name='tttt' value='' id='test' style='display:none'></body> </html> obj.click();好像在ff中不能使用 直接用type="file"这样的不行吗? <a href="javascript:upload();" >上传<img src="img.jpgg" alt="" /></a><input type="hidden" name="tryfile" id="tryfile" /> <input type="file" name="upLoadFileTry" style="display:none;" id="upLoadFileTry"/> function upload() { document.getElementById("tryfile").click(); document.getElementById("tryfile").value=document.getElementById("upLoadFileTry").value; } ie可以,ff不行,ff认为file框的点击是必须手动去点的. 是呀,没办法只能做个透明的file,然后将图像定位到file上了. <div id="fup" style="float:left; width:60"><span id="f1" style="position:absolute;padding-top:3; cursor:hand;font-family:宋体"><a href="##">add</a></span><span id="f2" onmouseover="this.scrollLeft=100" style="position:absolute;width:60;overflow:hidden;filter:alpha(opacity=0);opacity:0;-moz-opacity:0"></span></div><script language='javascript'> var upform = document.createElement('input'); upform.type = 'file'; upform.name = 'upload[]'; upform.size = 1; document.getElementById('f2').appendChild(upform); </script>这是网上找一高手的代码,呵呵,发出来. 这个地方有篇文章,专门关于file表单的click事件http://applefans.cn/?action=show&id=16 看来用透明后覆盖的方法应该可以,我去试验一下现在最麻烦的是我是要做成插件放到WYSIWYG编辑器里面去,而且打开门本对话框,点击ok后就要将文件上传就像163邮箱的附件添加一样!不知道这方法可不可行 用到javascript中的click()函数以及css样式的属性:display下面为html标签:<!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><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><script type="text/javascript">function show(){ file=document.getElementById("myfile"); file.style.display="block";}</script></head><body><a href="javascript:show();" >上传</a><input type="file" id="myfile" style="display:none" /></body></html> Allowed memory size of 8388608 bytes exhausted 获得不同IP用户数量的问题 PHP能调DLL么? linux 下 php用什么编译工具? 如何实现OA中的对WORD文档进行编辑的痕迹保留功能? 如何在下列函数中的字符串中显示一个变量的值 在linux下调试时,session出了问题!急!在线等待! 用php如何创建一个mysql的table? PHP获取搜索关键字问题 phpExcel导出excel2003表格,能够在浏览器中弹出对话框让其下载了? 文件路径问题 关于php多重继承问题
不过可以让系统点击一个隐藏的file表单来实现.<html>
<head>
<script type="text/javascript">
function openFileSelect()
{
var obj = document.getElementById('test');
obj.click();
}
</script>
</head>
<body>
<img src='xxx.gif' onclick='openFileSelect();'/>
<input type='file' name='tttt' value='' id='test' style='display:none'>
</body>
</html>
好像在ff中不能使用
<a href="javascript:upload();" >上传
<img src="img.jpgg" alt="" /></a>
<input type="hidden" name="tryfile" id="tryfile" />
<input type="file" name="upLoadFileTry" style="display:none;" id="upLoadFileTry"/>
function upload()
{
document.getElementById("tryfile").click();
document.getElementById("tryfile").value=document.getElementById("upLoadFileTry").value;
}
<span id="f1" style="position:absolute;padding-top:3; cursor:hand;font-family:宋体"><a href="##">add</a></span>
<span id="f2" onmouseover="this.scrollLeft=100" style="position:absolute;width:60;overflow:hidden;filter:alpha(opacity=0);opacity:0;-moz-opacity:0"></span>
</div>
<script language='javascript'>
var upform = document.createElement('input');
upform.type = 'file';
upform.name = 'upload[]';
upform.size = 1;
document.getElementById('f2').appendChild(upform);
</script>
这是网上找一高手的代码,呵呵,发出来.
现在最麻烦的是我是要做成插件放到WYSIWYG编辑器里面去,而且打开门本对话框,点击ok后就要将文件上传
就像163邮箱的附件添加一样!
不知道这方法可不可行
以及css样式的属性:display下面为html标签:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function show(){
file=document.getElementById("myfile");
file.style.display="block";
}
</script>
</head><body>
<a href="javascript:show();" >上传</a>
<input type="file" id="myfile" style="display:none" /></body>
</html>