JQuery QuickSearch:如果输入不为空则在加载时搜索

发布于 2024-08-26 02:13:37 字数 307 浏览 3 评论 0原文

我已经使用了 jquery fastsearch 插件,它工作正常,除了一个问题。我希望在加载页面时运行快速搜索。我创建了第二个快速搜索函数(在加载页面时调用)并将绑定更改为其他内容,但它在“加载”或“就绪”时不起作用。

如果我将绑定更改为“焦点”并将焦点放在文本字段上,它就可以工作,但仅限于 IE。

我想这样做的原因是因为用户离开页面时有一个“查看”链接。当他们回来时,我希望搜索结果与他们离开时一样。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哭了丶谁疼 2024-09-02 02:13:37

为您提供的懒惰解决方案:

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

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})
十年九夏 2024-09-02 02:13:37

其实仔细想想,
这可能是因为 doc.ready 不是在所有 js 加载时完成的,所以当你在页面加载时调用它时,快速搜索插件还没有完成初始化。

相反,您应该在插件初始化时使用回调

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

夜司空 2024-09-02 02:13:37

您可以使用:

'onAfter': function ()

更多功能:

$('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);
}

});

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);
}

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文