如何使输入密钥进程在jquery中工作

时间:2018-04-13 07:11:20

标签: jquery

如何使输入密钥进程在jquery中工作。当按下输入时,它将被处理。

DEMO

$(document).on('click', '#top-search-form .search-button', function (e) {

    e.preventDefault();
    var targrt = $(this).prev('input.search-input');
    targrt.animate({
        width: ["toggle", "swing"],
        height: ["toggle", "swing"],
        opacity: "toggle"
    }, 500, "linear");

    return false;
});

HTML

<form id="top-search-form" class="header-search-light">
    <input type="text" class="search-input" placeholder="Search...." required="" style="display: none;">
    <button class="search-button">
        <i class="fa fa-search" aria-hidden="true"></i>
    </button>
</form>

1 个答案:

答案 0 :(得分:0)

你可以尝试这样的事情。

$('.search-input').keypress(function (e) {
    if (e.which == 13) {
    ////////// Do your further action here

        var target = $(this);
        target.animate({
            width: ["toggle", "swing"],
            height: ["toggle", "swing"],
            opacity: "toggle"
        }, 500, "linear");

        return false;
    }
});