【发布时间】:2021-12-07 09:26:32
【问题描述】:
我有以下非常简单的 HTML 并且在 js 脚本的 if 语句中,我只是想在有人输入“Enter”按钮时插入一个额外的功能 - 但 Idk 为什么它不起作用!
document.querySelector(".subText").addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
let x = document.querySelector("#fname").value;
console.log(x);
}
});
<body>
<div class="wrapper">
<div class="container">
<div class="toDo">
<!-- <svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512">
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M224 184h128m-128 72h128m-128 71h128"/>
<path d="M448 258c0-106-86-192-192-192S64 152 64 258s86 192 192 192 192-86 192-192z" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="32"/>
<circle cx="168" cy="184" r="8" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/>
<circle cx="168" cy="257" r="8" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/>
<circle cx="168" cy="328" r="8" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/>
</svg> -->
<p class="toDoText">To-do List</p>
</div>
<div>
<input type="text" id="fname" name="fname" placeholder="I need to..." class="inputText">
<input type="submit" value="Submit" class="subText" onclick="addNote()">
</div>
</div>
<div class="test">
<!-- <div class="notesList">
<p class="notesInput">ddbd</p>
<button class="deleteBut" onclick="deleFunc()">
</button>
</div> -->
</div>
</div>
</body>
【问题讨论】:
标签: javascript addeventlistener appendchild queryselector