Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jquery mobile中如何在非ajax导航中显示加载程序?_Jquery_Jquery Mobile - Fatal编程技术网

在jquery mobile中如何在非ajax导航中显示加载程序?

在jquery mobile中如何在非ajax导航中显示加载程序?,jquery,jquery-mobile,Jquery,Jquery Mobile,我不希望在jquery mobile中使用基于非ajax的导航,因为我希望在每个页面上加载并运行特定的脚本。但问题是,当我在jquery mobile中使用非基于ajax的导航时。装载机没有出现。我通过使用 data-ajax="false" 每一个锚链 有没有一种快速的方法可以在每次页面转换时显示加载器,而不必编写自定义函数 我认为禁用ajax的微调器是不可能的。我的意思是,你可以在页面加载之前或之后闪烁一秒钟,但这有点违背了目的。不过,我知道在特定页面上加载和运行特定脚本是可能的。所以,也

我不希望在jquery mobile中使用基于非ajax的导航,因为我希望在每个页面上加载并运行特定的脚本。但问题是,当我在jquery mobile中使用非基于ajax的导航时。装载机没有出现。我通过使用

data-ajax="false"
每一个锚链


有没有一种快速的方法可以在每次页面转换时显示加载器,而不必编写自定义函数

我认为禁用ajax的微调器是不可能的。我的意思是,你可以在页面加载之前或之后闪烁一秒钟,但这有点违背了目的。不过,我知道在特定页面上加载和运行特定脚本是可能的。所以,也许你的问题应该是如何让特定的脚本在特定的JQM页面中运行

绑定到pageinit将帮助您为特定页面执行自己的javascript。以下仅在加载id为page2的JQM页面时执行。只需将其放入一个外部脚本中,并在页面的头部链接到它

$(document).on('pageinit','#page2',function(){
    $('#appendMe').append('This text was appended');    
});
如果要加载外部脚本/库,请使用$.getScript();方法。在我的示例中,我将在加载id为page3的JQM页面时加载并执行库。js只是在页面中添加了一个小微调器

​​$(document).on('pageinit','#page3',function(){
    $.getScript('http://fgnass.github.com/spin.js/dist/spin.min.js', function(){
        //the following code gets executed after spin.js is loaded
        var opts = {
            lines: 13, // The number of lines to draw
            length: 7, // The length of each line
            width: 4, // The line thickness
            radius: 10, // The radius of the inner circle
            rotate: 0, // The rotation offset
            color: '#000', // #rgb or #rrggbb
            speed: 1, // Rounds per second
            trail: 60, // Afterglow percentage
            shadow: false, // Whether to render a shadow
            hwaccel: false, // Whether to use hardware acceleration
            className: 'spinner', // The CSS class to assign to the spinner
            zIndex: 2e9, // The z-index (defaults to 2000000000)
            top: 'auto', // Top position relative to parent in px
            left: 'auto' // Left position relative to parent in px
        };
        var target = document.getElementById('spin');
        var spinner = new Spinner(opts).spin(target);
    });
});​​​​​​​​​​​​​​​​

这是一个让你相信我不是在瞎编的例子。呵呵

有一种客户端方法可以显示/隐藏加载程序:

$.mobile.showPageLoadingMsg()


$.mobile.hidePageLoadingMsg()

我认为唯一的方法是使用自定义函数,即,
$('*[data ajax=false]')。单击(function(){$('#loader')。fadeIn(100);})是的,但是在切换到禁用ajax的新页面时,这不起作用。我可以对类执行同样的操作吗。我的意思是,对于带有特定类而不是ID的页面,你是对的。而不是禁用ajax。我应该试着在PageInit上运行这个函数,我不明白为什么不能使用类。我想我还没有试过,但我确信它的工作原理是一样的$(document).on('pageinit','#page3',function()在jquery mobile上不起作用,而是使用了$('#page3').live('pageinit',function()。否则,您指导了我正确的方向。感谢您检查JSFIDLE示例,但它确实需要jquery 1.7+。live()方法已被弃用。如果您是jQuery 1.7之前的版本,我建议您使用委托,甚至是绑定。live存在许多报告问题。文档建议您在此处使用此方法