2 回答

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以使用輸入的事件,如onchange,onkeyup,onkeydown根據(jù)您的需要等。
function processString()
{
var searchString = document.getElementById("search").value;
console.log('Search key :'+ searchString);
// You can do your search code here
/*
if (cell.includes(searchString))
{
cell.visibility = "hidden";
}
*/
}
<input type="text" placeholder="Search" id="search" onkeyup="processString()">

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊
我想你想要這樣的東西。我曾經(jīng)做過(guò)的事
var searchRequest = null; //prevent multiple unnecessary requests to the server.
$(function () {
var minlength = 3;
$("#sample_search").keyup(function () {
var that = this,
value = $(this).val();
if (value.length >= minlength ) {
if (searchRequest != null)
searchRequest.abort();
searchRequest = $.ajax({
type: "GET",
url: "sample.php",
data: {
'search_keyword' : value
},
dataType: "text",
success: function(msg){
//we need to check if the value is the same
if (value==$(that).val()) {
//Receiving the result of search here
}
}
});
}
});
});
添加回答
舉報(bào)