在我的 Electron 应用程序中,我有一个功能可以在按下按钮时清除我的输入字段,但是在使用它之后,我无法再单击并输入输入。但是,如果我打开检查器窗口,它们会再次工作。
为什么会发生这种情况,我该如何解决?
Electron 应用的 main.js:
const { app, BrowserWindow, Menu } = require('electron');
let win;
function createWindow() {
win = new BrowserWindow();
win.loadFile('window_main/index.html');
}
app.on('ready', createWindow);
索引.html
<body>
<input type="text" id="testinput" />
<button id="clear">Clear</button>
<script src="index.js" type="text/javascript"></script>
</body>
index.js 中 JS 的问题:
document.getElementById('clear').addEventListener("click", clear);
function clear() {
if (confirm("Clear all inputs?")) {
document.querySelectorAll('input').forEach((input) => {
input.value = '';
})
}
}
最佳答案
我在删除脚本后复制了您的代码,该脚本未解释您使用它的原因,无论如何下面是使用 jQuery 的代码可以解决问题,这至少应该让您找到正确的位置..如果仍然无法与您合作发布更好地解释您的代码以获得更好的帮助...
如果它解决了您的问题,请将其标记为已回答....
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<title>Document</title>
</head>
<body>
<input type="text" id="testinput" />
<button id="clear">Clear</button>
<script>
$(document).ready(()=>{
document.getElementById('clear').addEventListener("click", clear);
})
function clear() {
if (confirm("Clear all inputs?")) {
document.querySelectorAll('input').forEach((input) => {
$(input).val('');
})
}
}
</script>
</body>
</html>
关于javascript - 清除它们后输入字段死了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59799629/