简体   繁体   English

如何使搜索仅在按 Enter 键时才起作用?

[英]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.

相关问题 如何仅在用户按下 Enter 按钮时进行搜索? - How do I search only when user press enter button? 当我搜索我的站点并按Enter键时,搜索可以正确执行,但是按按钮时,搜索却没有 - When I search my site and hit the enter key, the search performs correctly, but hitting the button, it does not 当我在文本框中输入单词并按空格键时,如何将输入的单词变成一个单独的短语,如何创建文本框? - How can I create a text box when I enter words in text box and hit spacebar it has to make entered words into a separate phrase? 当我按回车键时,我试图阻止默认行为,但它不起作用 - I'm trying to prevent default behavior when I hit enter but it doesn't work 我按键盘上的ENTER键,页面刷新。 如何防止这种情况,仍然使用键盘进行搜索? - I hit the ENTER key on keyboard and page refreshes. How do I prevent this and still use the keyboard to search? 这将打开正确的提示,但是当我按下Enter键时,什么也没发生 - This opens to the correct prompt, but when I hit enter nothing happens 当我在文本框上按Enter键时,为什么要提交表单? - Why is my form submitting when I hit enter on a textbox? 当您使用IIFE按下Enter键时,我想显示文本 - I want to display the text when you hit enter using IIFE 当我在动态路由上按 Enter 时,VueJS 动态路由隐藏? - VueJS dynamic route hide when I hit enter on dynamic routes? 当您按下Enter键时,我希望我的表格继续进行 - I want my form to progress when you hit the enter key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM