jQuery Mobile-在浏览其他页面后javascript停止工作 [英] jquery Mobile - javascript stops working after navigating other page

查看:68
本文介绍了jQuery Mobile-在浏览其他页面后javascript停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新版本的jquery mobile.一切正常.我有一些自定义的外部和内部JS脚本.主页上有一个jquery幻灯片显示,效果很好,但是当我导航到另一个页面并返回首页时通过按后退"按钮或单击任何链接的页面,幻灯片将停止工作.

I am using jquery mobile latest version.Everything works fine.I have some custom external and internal JS script.There is a jquery slideshow in the home page, it works well but when I navigate to another page and back to the home page by pressing back button or clicking any link, the slideshow stops working.

如果我在这些链接中添加data-ajax="false",则幻灯片在每种情况下都可以正常运行.但是我不想使用data-ajax="false"进行快速响应.我怎么解决这个问题?我对jquery mobile有点陌生.

If I add in those link data-ajax="false" , then the slideshow works well in every case.But I don't want to use data-ajax="false" for quick response. How can I solve this problem? I am little bit new in jquery mobile.

推荐答案

根据 docs ,当您在jQuery Mobile中的页面之间导航时,默认情况下将重新加载内容.当您使用data-ajax="false"强制jQuery Mobile完全重新加载页面时,因此脚本可以正常工作.

According to the docs when you navigate between pages in jQuery Mobile the content is being reloaded by default. When you're using data-ajax="false" that forces jQuery Mobile to completely reload the page, so your scripts are working.

似乎您有以下幻灯片呼叫:

It seems that you have following slideshow call:

$(function(){
     // init gallery on DOM ready
     $('.gallery').slideshow();
});

但是,当您使用jQuery Mobile在页面之间导航时,需要在重新加载某些页面时重新初始化图库,因此通用代码如下所示:

But when you're using jQuery Mobile to navigate between pages you'll need to reinitialize your gallery when certain page reloaded, so the universal code will look like following:

$(document).bind('pageinit', function() {
     // init gallery when current page loaded
     $('.gallery').slideshow();
});

这篇关于jQuery Mobile-在浏览其他页面后javascript停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆