jQuery 移动和PhoneGap deviceReady() 未触发

发布于 2024-12-26 09:47:57 字数 5512 浏览 0 评论 0原文

我正在尝试使用 PhoneGap 1.3.0 创建一个新的 Android 项目。和 JqueryMobile。但问题是,如果我使用 Only Phone Gap 测试代码 Phone Gap 有效! DeviceReady 函数被触发。请查看示例

<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 代码和 jQuery 库。

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

谢谢,

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>

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>

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七分※倦醒 2025-01-02 09:47:57

这是等价的;

$(document).ready(function() {
  // Handler for .ready() called.
  document.addEventListener("deviceready", onDeviceReady, true);
});

This is the equivalent;

$(document).ready(function() {
  // Handler for .ready() called.
  document.addEventListener("deviceready", onDeviceReady, true);
});
木緿 2025-01-02 09:47:57

您将 document.addEventListener("deviceready", onDeviceReady, true); 放置在 init 内,但从未真正调用它来进行初始化。因此 deviceready 的侦听器未附加。尝试更改为:

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

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);
});
伴随着你 2025-01-02 09:47:57

当我将项目转换为包含 iPhone 时,我必须更改为 document.addEventListener

When I converted my project to include iPhone I had to change to document.addEventListener.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文