本文介绍了jQuery Mobile的&放大器; PhoneGap的deviceReady()不解雇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建与PhoneGap的1.3.0新的Andr​​oid项目。和JqueryMobile。但德问题是,如果我只用电话GAP测试code电话峡的作品! DeviceReady功能被激活。请看看examles

i am trying to create a new Android project with PhoneGap 1.3.0. and JqueryMobile. But te problem is, if i use Only Phone Gap test code Phone Gap works! DeviceReady function is fired. Please look the examles

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test Page</title>
<link rel="stylesheet"  href="jquery.mobile/jquery.mobile-1.0.css" />
<link rel="stylesheet" href="docs/assets/css/jqm-docs.css" />
<link rel="stylesheet" href="docsdemos-style-override.css" />
<script type="text/javascript" src="jquery.mobile/jquery-1.6.4.min"></script>
<script type="text/javascript" src="jquery.mobile/jquery.mobile-1.0.js"></script>
<script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script>
<script type="text/javascript" charset="utf-8">


    var onDeviceReady = function() {
        document.getElementById("devready").innerHTML = "OnDeviceReady fired.";
    };

    function init() {
        document.addEventListener("deviceready", onDeviceReady, true);
    }   
</script>  
</head> 
<body > 

<div data-role="page" id="konum" data-theme="a">
<div data-role="header">
<h1>Position</h1>
</div>
<div data-role="content"> 
<p>APP will go here.</p>
<p>
<span id="devready">DeviceReady() Not Fired.</span>
</p>
</div>

但我想使用jQuery分页功能。而结果是:Deviceready不会被触发。有什么问题。它是如何可能同时使用PhoneGap的JavaScript的codeS和jQuery库。

But i want to use jQuery paging functionality. And the result: Deviceready not fired. What is the problem. How it is possible to use both PhoneGap javascript codes and jQuery library.

    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Test Page</title>

    <link rel="stylesheet"  href="jquery.mobile/jquery.mobile-1.0.css" />
    <link rel="stylesheet" href="docs/assets/css/jqm-docs.css" />
    <link rel="stylesheet" href="docsdemos-style-override.css" />
    <script type="text/javascript" src="jquery.mobile/jquery-1.6.4.min"></script>
    <script type="text/javascript" src="jquery.mobile/jquery.mobile-1.0.js"></script>
    <script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script>
    <script type="text/javascript" charset="utf-8">


        var onDeviceReady = function() {
            document.getElementById("devready").innerHTML = "OnDeviceReady fired.";
        };

        function init() {
            document.addEventListener("deviceready", onDeviceReady, true);
        }   
    </script>  
    </head> 
    <body > 
    <div data-role="page" id="home" data-theme="a">

    <div data-role="header">
    <h1>Home</h1>
    </div>

    <div data-role="content"> 
    <div data-role="content" id="twitList" >
    something will go here
    </div>   
    </div>
    <div data-role="footer" data-id="foo1" data-position="fixed">
        <div data-role="navbar">
        <ul>
            <li><a href="#home" id="home" data-icon="custom">Home</a></li>
            <li><a href="#about" id="about" data-icon="custom">About</a></li>
            <li><a href="#konum" id="konum" data-icon="custom">Position</a></li>
            <li><a href="#contact" id="contact" data-icon="custom">Contact</a></li>
        </ul>
        </div>
    </div>  
    </div>

    <!------page seperator --------> 

    <div data-role="page" id="about" data-theme="a">

    <div data-role="header">
    <h1>About</h1>
    </div>

    <div data-role="content"> 
    <p>Hoopp! <a href="#home">Back</a></p>    
    </div>
   <div data-role="footer" data-id="foo1" data-position="fixed">
        <div data-role="navbar">
        <ul>
            <li><a href="#home" id="home" data-icon="custom">Home</a></li>
            <li><a href="#about" id="about" data-icon="custom">About</a></li>
            <li><a href="#konum" id="konum" data-icon="custom">Position</a></li>
            <li><a href="#contact" id="contact" data-icon="custom">Contact</a></li>
        </ul>
        </div>
    </div>  
    </div>
    <!------page seperator --------> 


    <div data-role="page" id="konum" data-theme="a">

    <div data-role="header">
    <h1>Position</h1>
    </div>

    <div data-role="content"> 


    <p>APP will go here.</p>
    <p>
    <span id="devready">DeviceReady() Not Fired.</span>
    </p>

    </div>
    <div data-role="footer" data-id="foo1" data-position="fixed">
        <div data-role="navbar">
        <ul>
            <li><a href="#home" id="home" data-icon="custom">Home</a></li>
            <li><a href="#about" id="about" data-icon="custom">About</a></li>
            <li><a href="#konum" id="konum" data-icon="custom">Position</a></li>
            <li><a href="#contact" id="contact" data-icon="custom">Contact</a></li>
        </ul>
        </div>
    </div>  
    </div>

    </body>

谢谢

推荐答案

您放在 document.addEventListener(deviceready,onDeviceReady,真); 的init ,但从来没有真正把它做初始化。因此,侦听器 deviceready 未连接。请尝试更改为:

You placed document.addEventListener("deviceready", onDeviceReady, true); inside init but never actually call it to make initialization. So the listener for deviceready is not attached. Try changing to:

$(function() {
    document.addEventListener("deviceready", onDeviceReady, true);
});

这篇关于jQuery Mobile的&放大器; PhoneGap的deviceReady()不解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 13:04