gpt4 book ai didi

javascript - Electron - 文本区域对更改事件没有反应

转载 作者:行者123 更新时间:2023-12-03 12:25:20 29 4
gpt4 key购买 nike

我的 Electron 应用程序中有以下代码。首先我初始化它:

app.on('ready', createWindow);

function createWindow() {
window.loadURL(url.format({
pathname: path.join(__dirname, 'technical/views/highlightRules.html'),
protocol: 'file:',
slashes: true
}));
}

我的 highlightRules.html 包含以下内容

<script type="text/javascript" src="../../ioadapters/controllers/HighlightRulesController.js"></script>

...

<textarea id="lowValueSettingText" rows="8"></textarea>

最后 HighlightRulesController.js 有以下内容:

function setUp() {
const lowValueSettingTextarea = document.getElementById("lowValueSettingText");

lowValueSettingTextarea.onchange = function() {
onLowValueHighlightSettingChanged();
}
}

function onLowValueHighlightSettingChanged() {
alert("test");
}

setUp();

当我在 textarea 中输入内容并且它失去焦点时,不会显示任何警报。我希望执行 onLowValueHighlightSettingChanged 函数。
我怎样才能让它工作?

最佳答案

我发现出了什么问题。我将 highlightRules.html 中的标签放入头部区域。
一旦我把它移到 body 的底部,它就开始工作了。
放置脚本标签的正确位置:

<body>
...

<script type="text/javascript" src="../../ioadapters/controllers/HighlightRulesController.js"></script>
</body>

关于javascript - Electron - 文本区域对更改事件没有反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63440224/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com