About Input Search History Listing

Asked 2 years ago, Updated 2 years ago, 83 views

Thank you for your help.
Is there anyone who implemented the list of input search history in monaca like the image below?
Or how about this method?I would appreciate it if you could share it with me.

Reference Image

monaca

2022-09-30 21:12

1 Answers

I think using HTML5 Suggest is the best shortcut.

// Search history array
var history_list = [ ];

function fake_search(){
  // Retrieve and clear search terms
  varsword=$("#s_words").val();
  $("#s_words").val("";
  
  // Add if not already registered
  if(0>$.inArray(sword, history_list)){
    // Add history to Suggest
    $("#search_history").append($("<option>").val(sword));
    // Add to word list
    history_list.push(sword);
  }
  
  alert("Pseudosearched.\n Added words and phrases to search history.");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="search" id="s_words" name="s_words"placeholder="Please enter a search term." list="search_history"/>
<button onclick="fake_search();">Search</button>
<datalist id="search_history">
</datalist>

*The above example uses jQuery to make it easier.


2022-09-30 21:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.