xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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();
            // }
        });
    },

posted @ 2018-11-26 10:32  xgqfrms  阅读(302)  评论(0编辑  收藏  举报