使用jQuery Mobile转换页面后如何执行JavaScript [英] How to execute JavaScript after a page is transitioned with jQuery Mobile

查看:62
本文介绍了使用jQuery Mobile转换页面后如何执行JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个页面过渡到另一个页面(并使用location.hash东西)时,第二个页面不会加载任何JavaScript.加载页面时如何执行JavaScript(如果该页面来自"其父页面的过渡)?

When a page do a transition to another (and use the location.hash stuff) , this second page does not load any JavaScript. How can I execute JavaScript when a page is loaded (if this one "comes" from a transition from its parent) ?

我有page1.html,带有指向page2.html的链接.此page2.html加载时带有过渡效果(默认为幻灯片效果).

I have page1.html, with a link to page2.html. This page2.html loads with a transition (slide effect by default).

在page2.html中,不执行任何JavaScript.我尝试了一个简单的

In page2.html no JavaScript is executed. I tried with a simple

<script type="text/javascript">
alert("x");
</script>

但不起作用.我尝试了很多document.readybindliveoncreatepagecreate等.

but does not work. I tried with a lot of document.ready, bind, live, oncreate, pagecreate, and so on.

推荐答案

基本上在Jquerymobile中,当您只进行页面转换时,内部的内容

Basically in Jquerymobile when you do a page transition only the content inside

    <div data-role="page">
    ...
    </div> 

如此高效地更改了您的所有脚本以及其中包含的所有内容

gets changed so effectively all your scripts and everything you have included in

    <head></head> 

标签未加载.

因此,要解决此问题,您需要在页面内添加脚本,如下所示

So to solve this you need to include your script inside the page, like below

    <div data-role="page">
    ...
    <script type="text/javascript" src="yourScript.js"></script>
    </div>

谢谢, Dinesh Parne

Thanks, Dinesh Parne

这篇关于使用jQuery Mobile转换页面后如何执行JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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