javascript - 为什么 DOM 我的事件不工作并且样式改变?
问题描述
首先,让我告诉你我的目的。如果条目为空,则会出现一个 divin,但是当输入某些内容时,divin 将是“display: none”。我希望发生这种情况,但如视频所示,如果输入值为空白并且有效,我告诉我不要按删除键,3 个单词和“我删除了数字 8”在屏幕录制中只出现了 3 次. 奇怪的是,当缓慢按下删除键时,divim 成功“显示:阻止”,但是当我握住手指而不拉它时(我在按键事件中尝试过)它不会那样做。您可以在我的 github 帐户上查看所有代码。完整代码:https ://github.com/BerkayAkgurgen/Film-ProjectAPI/tree/main
Screen Record
// key event
searchInput.addEventListener('keydown', e => {
let control = false
if (e.which == 8 && searchInput.value.trim() == "") {
control = true
} else {
control = false
}
if (control) {
e.preventDefault()
return
}
console.log(e.which);
})
where I check empty input
if (inputValue == "" || !isNaN(inputValue)) {
ui.clearInput()
ui.returnBack()
} else {
filmRequest.getDatas(inputValue)
.then(data => {
ui.displayResults(data)
ui.resultUI()
})
}
// Style Changes
returnBack() {
this.mostPopulerHeader.style.display = "block"
this.topParents.style.display = "grid"
this.resultHeader.style.display = "none"
this.resultParent.style.display = "none"
}
resultUI() {
this.mostPopulerHeader.style.display = "none"
this.topParents.style.display = "none"
this.resultHeader.style.display = "block"
this.resultParent.style.display = "grid"
}
解决方案
推荐阅读
- javascript - 如何使用三元运算符使用react返回jsx?
- reactjs - reactJS useState - 如何在多个代码块中设置变量
- python - 在 Python 中使用 Tkinter 的 .grid() 函数时,sticky="W" 未将文本与窗口左侧对齐
- node.js - 卷挂载在 docker-compose 中的工作原理
- javascript - 删除 y 轴边距
- html - 如何在 CSS 中没有任何内容的情况下设置 height=100%?
- spring-security - JHipster 微服务和网关 - 网关可扩展性
- python-3.x - Python:两列之间的时间差(以小时为单位)
- laravel - 在 Laravel 中使用 Unique
- .net - Cosmos DB 和 DevOps 自动化