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

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

问题描述

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

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

在 page2.html 中没有执行 JavaScript.我尝试了一个简单的

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

解决方案

基本上在 Jquerymobile 中,当你做一个页面转换时,只有里面的内容

 

...

非常有效地更改了您的所有脚本以及您包含在其中的所有内容

 

标签未加载.

所以要解决这个问题,您需要在页面中包含您的脚本,如下所示

 

...<script type="text/javascript" src="yourScript.js"></script>

谢谢,迪内什·帕恩

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) ?

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

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

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

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

解决方案

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> 

tags is not getting loaded.

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>

Thanks, Dinesh Parne

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

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