【问题标题】:Page not reloading页面未重新加载
【发布时间】:2015-09-23 19:21:22
【问题描述】:

我使用过 mobile.js。在我的应用程序中使用 phonegap 开发应用程序

请检查我的代码

index.html

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>PlayTradeWin</title>
        <link href="css/style.css" rel="stylesheet" type="text/css" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- Include jQuery Mobile stylesheets -->
        <link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css">

        <!-- Include the jQuery library -->
        <script src="cordova.js"></script>

        <!-- Include the jQuery library -->
        <script src="js/jquery-1.11.3.min.js"></script>
        <!-- Include the jQuery Mobile library -->
        <script src="js/jquery.mobile-1.4.5.min.js"></script>
        <script type="text/javascript">
          document.addEventListener("deviceready", onDeviceReady, false);
          function onDeviceReady() {
              //some js code here
          }
        </script>
     </head>
<body>
<a href="login.html" data-transition="flip">Login</a>
</body>
</html>

login.html

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>PlayTradeWin</title>
        <link href="css/style.css" rel="stylesheet" type="text/css" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- Include jQuery Mobile stylesheets -->
        <link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css">

        <!-- Include the jQuery library -->
        <script src="js/jquery-1.11.3.min.js"></script>
        <!-- Include the jQuery Mobile library -->
        <script src="js/jquery.mobile-1.4.5.min.js"></script>
         <script>
              alert("Hello");
         </script>
     </head>
<body>
   Login form here..
</body>
</html>

我的页面完美翻转,但是当我通过点击 index.html 页面中的 Login 链接将 index.html 转到 login.html 时,我的 JavaScript 警报不起作用。

【问题讨论】:

  • 您使用的是jquery mobile,当您使用jquery mobile时,您不会加载整个login.html页面,只需获取html内容,如果您想在login.html页面加载时执行代码,有相应的事件
  • 是的,我正在使用该事件。那也行不通。
  • 然后,显示你的代码
  • @jcesarmobile 告诉我如何使用移动事件加载?

标签: javascript android jquery html cordova


【解决方案1】:

使用

$( function() {
 alert('Hello');
});

【讨论】:

    【解决方案2】:

    我猜想这种类型的 js 脚本注入 HTML 是 Cordova 不支持的。您需要在 index.js 脚本中执行逻辑。

    此外,如果您希望执行警报,您可以使用 apache cordova 插件进行通知(您可以通过项目配置 --> 插件获取它)。

    【讨论】:

    • 是的,我使用了 index.js
    • cordova 插件未添加到我的项目中。你能告诉我如何添加这个吗?
    • 它现在对你有用还是还有其他问题?
    • 您在使用 Visual Studio 吗?您需要双击“config.xml”。在那里你会找到一个可以导入cordova插件的部分;)
    • config.xml文件中没有插件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-02
    • 2022-01-25
    • 2013-10-04
    • 2018-05-07
    • 1970-01-01
    相关资源
    最近更新 更多