简体   繁体   English

在jQuery移动页面中加载jQuery脚本

[英]Load jQuery script in jQuery mobile page

First post. 第一篇文章。

I have searched extensively for a clear cut answer, however I am more stuck than ever after reading for hours. 我已经在广泛的搜索中找到了明确的答案,但是在阅读了几个小时后,我比以往任何时候都更加困惑。

What I am trying to accomplish: I would like to be able to load a javascript live search script for 1 page (page1) on a multi page app. 我要完成的工作:我希望能够在多页应用程序上为1页(page1)加载javascript实时搜索脚本。 The search filters li items in a ul 搜索在ul中过滤li个项目

What I have learned: I have come to the conclusion after much searching that I cannot use document.ready and instead must bind it to pageinit. 我所学的:经过大量搜索后得出的结论是,我无法使用document.ready,而必须将其绑定到pageinit。

$('#page1').live('pageinit', function () {
$("#filter").keyup(function () {

    // Retrieve the input field text and reset the count to zero
    var filter = $(this).val();

    // Loop through the comment list
    $(".list li,h2").each(function () {

        // If the list item does not contain the text phrase fade it out
        if ($(this).text().search(new RegExp(filter, "i")) < 0) {
            $(this).fadeOut();

            // Show the list item if the phrase matches and increase the count by 1
        } else {
            $(this).show();
        }
    });
});
});

I have tried to alter my conditioning statements and I cannot find a solution. 我试图更改我的条件声明,但找不到解决方案。

Here is what I have thus far: http://jsfiddle.net/zb0t/L9t7G/ 到目前为止,这是我所拥有的: http : //jsfiddle.net/zb0t/L9t7G/

PS I have also tried simply adding jQuery mobiles data-filter="true" however, I could not figure out how to embed the search field into the header as it would simply stay fixed under the header and I could not call the data-mini="true". PS我也尝试过简单地添加jQuery mobiles data-filter =“ true”,但是,我无法弄清楚如何将搜索字段嵌入标头中,因为它将仅固定在标头下,并且无法调用data-mini =“ true”。

Thanks in advanced! 提前致谢!

Look at the console 看控制台

Uncaught TypeError: Object [object Object] has no method 'live' 

jQuery 1.9 does not have live , that was deprecated in 1.7 and removed in 1.9 jQuery 1.9没有live ,在1.7中已弃用,在1.9中已删除

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM