开发者

JQuery QuickSearch: Searching on load if the input isn't blank

开发者 https://www.devze.com 2022-12-24 09:28 出处:网络
I have used the jquery quicksearch plugin and it works fine, except for one problem. I would like the quicksearch to run when the page is loaded. I have created a second quicksearch function (which is

I have used the jquery quicksearch plugin and it works fine, except for one problem. I would like the quicksearch to run when the page is loaded. I have created a second quicksearch function (which is called when the page is loaded) and changed the bind to something else, but it won't work on "load" or "ready".

If I change the bind to "focus" and put the focus onto the textfield it works, but only in IE.

The reason I want to do this is because there is a "view" link where the user leaves the page. When they come back开发者_运维问答, I would like the search results to be as they left them.


lazy solution for you:

$(function(){
//$('search_input').attr('value', search_term); // optional - put something in the search box
$('search_input').keyup(); //trigger the search onload})


actually thinking about it, it's probably because doc.ready isnt when all js is loaded, so the quick search plugin isnt finished initialising when u call it on page load.

instead you should use a callback on the plugin initialisation


You can use:

'onAfter': function ()

More functions:

$('input#search').quicksearch('table tbody tr', {

'delay': 100,
'selector': 'th',
'stripeRows': ['odd', 'even'],
'loader': 'span.loading',
'noResults': 'tr#noresults',
'bind': 'keyup keydown',
'onBefore': function () {
    console.log('on before');
},
'onAfter': function () {
    console.log('on after');
},
'show': function () {
    $(this).addClass('show');
},
'hide': function () {
    $(this).removeClass('show');
}
'prepareQuery': function (val) {
    return new RegExp(val, "i");
},
'testQuery': function (query, txt, _row) {
    return query.test(txt);
}

});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号