简体   繁体   English

无法用电子输入文本/输入字段

[英]Cannot type into text/input field with electron

So I am developing an app (calendar) with electron. 因此,我正在开发一个带有电子的应用程序(日历)。 I have made this menu where you can add new events and so on. 我做了这个菜单,您可以在其中添加新事件等。 And I want the user to be able to enter the title of their event into a textbox/input field. 我希望用户能够在文本框/输入字段中输入事件的标题。 But when I create the element, I cannot type anything into it..? 但是,当我创建元素时,不能在其中输入任何内容。 This is how i have set it up: 这是我设置的方式:

var inputField = document.createElement("input");
    inputField.setAttribute("type", "text");
    inputField.setAttribute("value","Title");
var container = document.getElementById("mainCont");
    container.appendChild(inputField);

Why isn't this working..? 为什么这不起作用..? I have also tried wrapping everything up in a paragraph tag, but to no avail. 我也尝试过将所有内容包装在一个段落标签中,但无济于事。

In advance, thanks. 预先,谢谢。

Oh well, I found the answer.. It turns out that I have to 'focus' the input element when using electron. 哦,好了,我找到了答案。事实证明,使用电子时,我必须“聚焦”输入元件。 The solution: 解决方案:

 <script type="text/javascript" charset="utf-8">
  document.getElementsByTagName('input')[0].focus()
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM