如何触发榆树中的点击事件 [英] How to trigger click event in elm
问题描述
在简单的html + js应用程序中,当我需要打开一些交互式输入元素的对话(例如 input [type =file]
或输入[type =date]
或 input [type =color]
)任何非标准方式页面加载)最前进的方式是触发上面提到的元素点击
事件。但是我没有办法在纯榆树(没有港口)这样做。我看到DOM事件处理有 focus
触发器,但没有点击
。我错过了什么吗?
In simple html + js applications when I need to open dialogues of some interactive input elements (such as input[type="file"]
or input[type="date"]
or input[type="color"]
) any non-standard way (with a button or on page load) the most strait forward way is to trigger click
event on above mentioned elements. But I couldn't find a way to do that in pure elm (without ports). I see for DOM events manipulation there is focus
trigger, but no click
. Am I missing something? Is it not the "elm way" of doing things?
推荐答案
在文件中阅读MDN
Reading throught the MDN on File
element I saw they suggest to use <label>
to trigger the element without JavaScript
:
<input type="file" id="fileElem" multiple accept="image/*" style="display:none" onchange="handleFiles(this.files)">
<label for="fileElem">Select some files</label>
elm-fileinput https://developer.mozilla.org/ en / docs / Using_files_from_web_applications
找到一个库< input type =file>
: https://github.com/lovasoa/elm-fileinput 。
此外,我还使用这个lib中的解码器建立了一个工作示例: https://runelm.io/c/ie0 。
Also I have put up a working example using the decoder from this lib: https://runelm.io/c/ie0.
这篇关于如何触发榆树中的点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!