enter & keypress
enter & keypress
https://stackoverflow.com/questions/905222/enter-key-press-event-in-javascript
https://stackoverflow.com/questions/16011312/execute-function-on-enter-key
https://www.w3schools.com/jsref/event_onkeypress.asp
https://memorynotfound.com/detect-enter-keypress-javascript-jquery/
inputClickEnter() {
let that = this;
let input = document.querySelector(`[data-input="search"]`);
input.addEventListener(`keypress`, (e) => {
console.log(`press enter key`, e);
if (e.which === 13 || e.keyCode === 13) {
that.getSearchData();
}
});
},
demo
inputClickEnter() {
let that = this;
let input = document.querySelector(`[data-input="search"]`);
input.addEventListener(`keypress`, (e) => {
console.log(`press enter key`, e);
if (e.which === 13 || e.keyCode === 13 || e.key === "Enter" || e.charCode === 13 || e.code === "Enter") {
that.getSearchData();
}
// if (e.which === 13 || e.keyCode === 13 || e.key === "Enter") {
// that.getSearchData();
// }
// if (e.which === 13 || e.charCode === 13 || e.code === "Enter") {
// that.getSearchData();
// }
});
},
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/10018956.html
未经授权禁止转载,违者必究!