我有 1 个 textbar
,我想通过键盘上的 Enter 键 从用户那里获取值,然后运行一个函数(我的函数名称是 {{1} })。我的代码是这样的,对吗?
newNote
答案 0 :(得分:-1)
我尝试找到正确的答案:
function nameOfYourEventListener(){
document.querySelector("#yourInputID").addEventListener("keydown", function (e){
if (e.code === 'Enter'){
newNote(e); //function that you run for add the content to the list
}});
答案 1 :(得分:-2)
function eventListeners(){
let targetInput = document.querySelector('#inputId');
document.querySelector("#note").addEventListener("keypress", function (e){
if (e.key === "Enter"){
let value = target.value; // do something with the value
newNote();
}
})
}