Javascript在第二个html文件中不工作Phonegap& jQuery Mobile [英] Javascript not working in second html file in Phonegap & jQuery Mobile

查看:104
本文介绍了Javascript在第二个html文件中不工作Phonegap& jQuery Mobile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个Phonegap jQuery移动Android应用程序。该应用程序从默认的index.html页面开始,在其中我使用$ .mobile.changePage加载demo.html文件。 demo.html被加载并正确显示,但javascript不工作。我想我乱七八糟的jQuery Mobile的pageinit事件,或者我不知道如何使用它。



这是我的代码:



这发生在index.html中:

  $ .mobile.changePage .html,{
transition:slideup,
reverse:false,
changeHash:false
});

demo.html的代码:

 <!DOCTYPE HTML> 
< html>
< head>
< script type =text / javascript>
$('#demo-page')。live('pageinit',function(){
alert(Welcome);
});
< / script>
< / head>
< body>
< div data-role =pageid =demo-page>
< div data-role =header>
< h1>参观游览< / h1>
< / div>
< div data-role =contentid =demo-content>
< h2>这是演示页。< / h2>
< / div>
< / div>
< / body>
< / html>

因此,当demo.html显示时,Welcome警告不会执行。
我不知道这里发生了什么。

解决方案

它不工作,因为只加载第二页的正文部分。



放置此零件:

 < script type = / javascript> 
$('#demo-page')。live('pageinit',function(){
alert(Welcome);
});

 

只有这样的代码可以从demo.html执行,如果它作为外部链接加载。


I am working on an Phonegap jQuery mobile Android app. The app starts with the default index.html page and in it i am using $.mobile.changePage to load demo.html file. The demo.html gets loaded and displayed correctly but the javascript isn't working in it. I think i am messing up with the 'pageinit' event of jQuery Mobile or i don't know how to use it.

Here is my code :

This happens in index.html :

    $.mobile.changePage("demo.html", {
                                transition: "slideup",
                                reverse: false,
                                changeHash: false
                            });

And the code for demo.html :

<!DOCTYPE HTML>
<html>
  <head>
  <script type="text/javascript">
    $('#demo-page').live('pageinit', function(){
    alert("Welcome");
  });
  </script>
    </head>
    <body>
    <div data-role="page" id="demo-page" >
    <div data-role="header">
    <h1>Take a tour</h1>
    </div>
        <div data-role="content" id="demo-content">
            <h2>This is the demo page.</h2>
        </div>
    </div>
    </body>
</html>

So when the demo.html gets displayed, the 'Welcome' alert doesn't gets executed. I have no idea what is happening here.

解决方案

It is not working because only body part of a second page is loaded.

Put this part:

<script type="text/javascript">
    $('#demo-page').live('pageinit', function(){
        alert("Welcome");
    });
</script>

into the index.html.

Only way this code can be executed from demo.html is if it was loaded as an external link.

这篇关于Javascript在第二个html文件中不工作Phonegap&amp; jQuery Mobile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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