移动端 input 输入框使软键盘回车键变为搜索按钮

HTML iOS About 473 words

设置 type=search

注意:iOS必须添加form且添加action

<form action="#" onsubmit="return false">
    <input class="search-input" placeholder="请输入关键字..." type="search" results="10">
    <button type="button" class="search-button">搜索</button>
</form>

监听回车事件

使用jQuery方式

$('.search-button').click(function () {
    let keyword = $('.search-input').val().trim();
    if (keyword.length > 0) {
        window.location.href = "/search/"+keyword+".html"
    }
});
Views: 5,049 · Posted: 2019-06-15

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓
Today On History
Browsing Refresh