js文件里实现点击一个图标,弹出选择图片的对话框

类似这种对话框,选择文件后点击打开,就能将图片传入到编辑器里。图标不是用html定义的,是用js文件在extjs里定义的,现在就缺一个点击图标的事件。希望有有用的代码。

第1个回答  2014-04-27
这个功能一般都是html做的。

<form>
<input type="file" />
</form>

呵呵,就这么简单,不过具体传到哪里去,那就是后台人员的事了。
第2个回答  推荐于2016-07-09
1、可以使用trigger方式,javascript中没有原生的trigger函数,可以自己写一个,也可以直接使用jquery的实现:

[javascript]
var button1 = document.getElementById("button1");
var button2 = document.getElementById("button2");
button1.onclick = function(){alert("button1");trigger(button2,"onclick");}
button2.onclick = function(){alert("button2");}
function trigger(ele,event)
{ele[event]();}

2、也可以使用更加简单的方式,就是将input覆盖住要点击的图片或者超链或者其它div,然后将input设置成完全透明,这样点击图片时其实点击的是input,如下:

[html]
<div class="ps-image" style="width:300px;height:300px;border:0px sold red; background:url('/images/ps.png')">
<input type="file" id="file" style="filter:alpha(opacity=0);opacity:0;width:100%;height:100%;"/>
</div>
相似回答