example.html 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
  6. <script src="./jssearch.js"></script>
  7. <script src="./jssearch.index.js"></script>
  8. <script type="text/javascript">
  9. $( document ).ready(function() {
  10. $('#searchbox').on("keyup", function() {
  11. var result = jssearch.search($(this).val());
  12. $('#query').html(jssearch.queryWords.join(' '));
  13. $('#results').html('');
  14. var i = 0;
  15. result.forEach(function(item) {
  16. if (i++ > 20) {
  17. return;
  18. }
  19. var div = $('#results');
  20. div.html(div.html() + '<li>"' + item.file.title + '" ' + item.file.url + ' w:' + item.weight + '</li>');
  21. });
  22. });
  23. });
  24. </script>
  25. <title>Example</title>
  26. </head>
  27. <body>
  28. <h1>Example</h1>
  29. <label for="searchbox" style="display: inline-block; width: 160px;">Search: </label>
  30. <input id="searchbox" type="text" value="">
  31. <br/>
  32. <label for="query" style="display: inline-block; width: 160px;">Actual query: </label>
  33. <span id="query"></span>
  34. <ul id="results">
  35. <li>No results</li>
  36. </ul>
  37. </body>
  38. </html>