1
正如在標題中,我試圖使AJAX添加到我的網站上的搜索框,但keyup事件沒有解僱。我使用的函數從該消息https://stackoverflow.com/a/17317620/5690756jQuery輸入類型的文本沒有觸發鍵盤事件
反正這裏是我的代碼
<nav id="search" class="search-main">
<div class="search-trigger"></div>
<div class="search-general">
<div class="search-close"></div>
<input type="text" value="" id="autocomplete" name="s" class="search-input ui-autocomplete-input" placeholder="Arama" autocomplete="off">
<input type="button" class="search-button">
和JS代碼
jQuery(document).ready(function($) {
$("#autocomplate").on('change keyup paste', function() {
alert("Girdim");
var lastValue = $("#autocomplate").val();
jQuery.ajax({
type : 'post',
url : helper.ajaxUrl,
data : {action : 'load_search_results',query : lastValue
},
beforeSend: function() {
$(this).prop('disabled', true);
},
success : function(response) {
$(this).prop('disabled', false);
$('#modal_results').html(response);
}
});
});
});
報警功能在我的代碼不工作我該如何解決這個問題,我有不知道。
編輯: 我有另一個父元素的功能。它可以阻止輸入功能,我還添加了HTML代碼,以清楚起見。
$("#search").click(function() {
if($(this).attr("class")=="search-main"){
$(this).attr("class","search-main expand");
$("#autocomplete").attr("placeholder","Lütfen dizi, oyuncu veya tür adı yazın.");
$("#autocomplete").focus();
}
return false;
});
感謝
它在這裏工作http://jsfiddle.net/tg5op333/9/如果有任何錯誤,請參閱您的控制檯 –
是在頁面加載時#autocomplate輸入HTML的一部分或在頁面被加載後附加到HTML加載? –
不,它是wordpress上的header.php文件,控制檯上沒有錯誤。我在開發者控制檯上禁用了緩存,並且沒有結果 –