[英]How I make the search only work when I hit enter?
I have search box and I'm using this code to show the results from mysql databse with almost 9,000,000 raw But becuse I have big database I want it to only show the results when someone type a word and then hit enter, and no data rendering when someone open the page.我有搜索框,我正在使用此代码显示来自 mysql 数据库的结果,原始数据接近 9,000,000 但因为我有大数据库,我希望它仅在有人输入单词然后按 Enter 时才显示结果,而没有数据呈现当有人打开页面时。 By defults it's live search box right now
默认情况下,它现在是实时搜索框
This is my code: but it doesnt work?这是我的代码:但它不起作用?
$('#search_text').keyup(function(){
var search = $(this).val();
if(search != '')
if (event.key === "Enter")
{
load_data(search);
}
else
{
load_data();
}
});
Just remove the load_data
call in your else
and return
out of the function:只需删除
else
中的load_data
调用并return
函数:
$('#search_text').keyup(function(){
var search = $(this).val();
if(search != '') {
if (event.key === "Enter") {
load_data(search);
} else {
return;
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.