javascript - 学习 JS - 无法将计数器的结果用于字段
问题描述
我真的很陌生,所以请原谅我的无知。
我正在尝试通过添加错误计数器来改进练习打字速度代码。我设法在 HTML 和 css 上为计数器添加了新字段。但是,我只是没有设法将错误计数器的结果放在这个新创建的字段中。我已经制作了计数器的 console.log,它工作正常。任何帮助表示赞赏。问候。
我尝试了使用 innerHTML 和不同字段的各种变体,但均未成功。
<!--HTML-->
<section class="error-counter-area">
<h5 id="ectitle">ERROR COUNTER</h5>
<div class="error-counter">0000</div>
</section>
//JS
const theErrorCounter = document.querySelector(".error-counter");
//var errorCounter = 0000; //Initial 4 digits format for errorCounter, but I don't know how to make it work in the same time with the counter inside the function...
function errorCounterRun() {
var i = 0;
errorCounter = i++;
theErrorCounter.innerHTML = errorCounter;
console.log(errorCounter); // This works fine, it counts except that it is counting the backspace too, but that is another problem...
}
计数器应显示在 errorCounter H5 字段中,而不仅仅是在 console.log 中。
解决方案
推荐阅读
- java - 限制每分钟 JWT 令牌的数量
- nginx - 用于通过 url 播放 .ogg 音频的 Nginx 配置
- reactjs - 如何在材质 UI 中的深色和浅色主题之间为 Paper 组件交换 2 种不同的背景颜色?
- android - 按下主页按钮时如何关闭溢出菜单?
- qt - Qml FontLoader 未加载自定义字体
- azure - 如何阻止“az login”更改我的默认订阅?
- flutter - 拖动滑块时调整字体大小
- sql - 在 SQL 中,即使日期没有数据点,有没有办法显示所有日期?
- python - TensorFlow 在一个 GPU 上同时训练多个较小的批次
- ios - AVCapturePhotoOutput didFinishProcessingPhoto 没有被调用