android - 第一次使用 jquery mobile 加载页面后事件不起作用

标签 android ios jquery-mobile cordova

我正在使用 JQM 1.1.0 和 Cordova 1.5.0。

我有这样的代码

<!DOCTYPE HTML>
<html>
<head>
<title>Index Page</title>

<!-- Adding viewport -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Adding Phonegap scripts -->
<script type="text/javascript" charset="utf-8"
src="cordova/cordova-1.5.0.js"></script>

<!-- Adding jQuery mobile and jQuery scripts & CSS -->
<script type="text/javascript" src="jquery/jquery-1.7.1.min.js"></script>
<link rel="stylesheet"
href="jquerymobile/jquery.mobile-1.1.0-rc.1.min.css" />
<script type="text/javascript" src="jquery/jquery.validate.min.js"></script>
<script type="text/javascript"
src="jquerymobile/jquery.mobile-1.1.0-rc.1.min.js"></script>
<link rel="stylesheet" href="css/colors.css">

<script type="text/javascript">

$("#page1").live("pageinit", function(e) {
console.log("pageinit1");
    }

$("#page2").live("pageinit", function(e) {
console.log("pageinit2");
    }
</script>
<body>
<div data-role="page" id="page1">
  <div data-role="header">Page 1</div>
  <div data-role="content"></div>
</div>

<div data-role="page" id="page2">
  <div data-role="header">Page 2</div>
  <div data-role="content"></div>
</div>
</body>

此代码在 Android 上运行良好。但在 iOS 中,一旦页面加载,page1 的 pageinit 事件就不会被触发,稍后如果我将页面更改为 page2 那么一切都很好..为什么会发生这种情况?

最佳答案

对此不太确定,但据我所知,JQ1.7.x 中的实时函数已发生变化,现在您必须使用 on() 函数,该函数对您的代码编码方式有一些细微的变化..

关于android - 第一次使用 jquery mobile 加载页面后事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10008186/

相关文章:

jquery - 添加 Jquery Mobile 会破坏 CSS

android - MvvmCross 安卓 ViewStub

java - EditText 上的“完成”按钮的监听器?

android - 将Admob添加到ScrollView -> AdBanner消失

ios - 从 .scn 文件加载后无法在 ARKit 场景中查看几何体

Jquery 移动触发器创建不更新 slider 按钮位置

java - MVP 中的观察者模式

ios - fatal error :Can't open realm

ios - 如何更改 iOS 自定义键盘的高度?

javascript - 如何在页面加载前禁用 jQuery Mobile 中的 Ajax?