简体   繁体   中英

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. 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:

$('#search_text').keyup(function(){
  var search = $(this).val();
  if(search != '') {
    if (event.key === "Enter") {
      load_data(search);
    } else {
      return;
    }
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM