0
我正在使用一些代碼(請參見下文)停止我的網站上的搜索按鈕,直到某些文本輸入搜索輸入字段。這很好,但是,在任何文本輸入之前,我仍然可以按下鍵盤上的'Enter'並觸發'空白'搜索 - 還有一種方法可以禁用「Enter」鍵直到某些文本有已經進入?在搜索輸入字段爲空時停止「輸入」鍵工作
<div class="standard-search-box">
<form class="search-form" action="/search">
<label for="q" id="search-label" class="screen-reader-text">Search</label>
<input aria-labelledby="search-label" id="q" type="search" name="q" class="search-field" placeholder="enter search term…" value autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
<input type="submit" value="Search" class="search-button" disabled="disabled">
</form>
</div>
(function() {
$('input.search-field').keyup(function() {
var empty = false;
$('input.search-field').each(function() {
if ($(this).val() == '') {
empty = true;
}
});
if (empty) {
$('input[type=submit]').attr('disabled', 'disabled');
} else {
$('input[type=submit]').removeAttr('disabled');
}
});
})();
任何幫助將不勝感激。
謝謝你,完美的工作。 – user3326054