如何使输入密钥进程在jquery中工作。当按下输入时,它将被处理。
$(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>
答案 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;
}
});