jquery - JavaScript- find text within a page and jump to location in page -
i have webpage large list of records (say 250+ rows of data in table) , want able visit page, start typing, , have jump me first row matches text have typed.
ideally, if continued type more characters first match doesn't match anymore, continue respond input , jump me new match.
i've tried window.find() haven't had success... can reccomend working solution?
i'm looking equivalent hitting 'ctrl-f' on keyboard... except without need hit ctrl-f make happen.
i think tricky part of accepting of user input intelligently. therefore, i'd best thing pass off searching autocomplete-type plugin. once page ready, pass focus input text box, , let plugin magic search...
for example, use quicksearch plugin.
then given table of data , input this:
<input id="searcher" type="text" name="searcher">
you have ready function looks this:
$('#searcher').quicksearch('table tbody tr', { 'delay': 100, 'bind': 'keyup keydown', 'show': function() { if ($('#searcher').val() === '') { return; } $(this).addclass('show'); }, 'onafter': function() { if ($('#searcher').val() === '') { return; } if ($('.show:first').length > 0){ $('html,body').scrolltop($('.show:first').offset().top); } }, 'hide': function() { $(this).removeclass('show'); }, 'preparequery': function(val) { return new regexp(val, "i"); }, 'testquery': function(query, txt, _row) { return query.test(txt); } }); $('#searcher').focus();
try out here: http://jsfiddle.net/zlhad/369/
edit: other answer/comment added in make input fixed , stop scollbar jumping around ridiculously.
Comments
Post a Comment