【问题标题】:Enter Key redirect输入键重定向
【发布时间】:2021-12-24 09:53:45
【问题描述】:

所以,我希望能够在文本字段中按 Enter 并被重定向到另一个页面。有谁知道我该怎么做?

<input class="center" type="text"  style="font-size:20px; border:none; outline:none; " size="105" type="text" placeholder="Shrek" name="search" >

【问题讨论】:

标签: javascript html


【解决方案1】:

编辑:替换单引号和双引号。

const search = document.querySelector('[name="search"]');

search.addEventListener('keyup', (e) => {
    if (e.code === 'Enter') {
        const url = 'https://example.com/';

        window.location.href = url;
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-31
    • 1970-01-01
    • 1970-01-01
    • 2014-06-19
    • 2014-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多