【发布时间】:2021-02-25 05:21:21
【问题描述】:
我正在创建一个 Google chrome 扩展程序,并试图让我的停止/停止日志记录按钮在我的名为 Logger 的函数中工作。按下按钮时,它不会对我编写的功能做出反应,目前它正在显示停止按钮,但我希望它在单击时显示开始按钮。我希望我能解释一下,但有人可能知道为什么我的功能不起作用吗?
下面是我当前的javascript函数和html:
popup.js
//attempt to get start/stop logging buttons to work
function Logger(isLogging, notLogging) {
if (isLogging = true, notLogging = false) {
addRow();
document.getElementById("click-start").style.display = "block";
document.getElementById("click-stop").style.display = "none";
}
if (isLogging = false, notLogging = true) {
document.getElementById("click-start").style.display= "none";
document.getElementById("click-stop").style.display= "block";
}
}
//button to start logging
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("click-start").addEventListener("click", Logger(true, false));
});
//button to stop logging
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("click-stop").addEventListener("click", Logger(false, true));
});
popup.html
<!--Start button of logging-->
<button class="button button1" id="click-start" >
<u> Start Logging </u>
</button>
<!--Stop button of logging-->
<button class="button button2" id="click-stop" >
<u> Stop Logging </u>
</button>
Image of current output--按钮目前没有反应
【问题讨论】:
-
除了你的实际问题,在 Logging() 函数中只使用一个参数,如果检查则做一个。 if (isLogging) { ... } else { ... }
标签: javascript html button google-chrome-extension getelementbyid