- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 jquery 移动网站,我在运行 javascript 代码时遇到了一些问题。
我有一个主页 index.html,它基本上是一个用于导航到各种 html 页面的 ListView 。我的页面使用单页结构,这意味着每个 1 个 html 文件包含 1 个页面。现在从主页,我导航到另一个我正在使用 persistent NavBar 的页面。带有一个带有 2 个选项的水平按钮。一个是照片,另一个是多媒体。
对于照片,我使用 Javascript FB API 从 FB 页面下载照片,然后使用 PhotoSwipe 插件将它们呈现给用户。
问题..
如果我运行 photos.html 页面,它将运行良好并加载相册。我的 javascript 做了两件事。 1) 使用 FB API 获取相册、照片、封面照片等。 2) 使用此相册及其照片动态创建 ListView 。在这种情况下,两者都很好用!
但是,当我在 index.html 中并通过 ListView 导航到 photos.html(照片是持久导航栏中默认选择的按钮)时,Javascript 代码不起作用。 Like 根本没有被调用..
index.html 看起来像:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Mobile Web App</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--<link href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" rel="stylesheet" type="text/css"/>-->
<link rel="stylesheet" href="themes/EspacioJoven.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile.structure-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<link rel="stylesheet" href="themes/custom.css" />
</head>
<body>
<div data-role="page" id="home" data-theme="a">
<!--
<div data-role="header">
<h1>Application Title</h1>
</div>
-->
<div data-role="content">
<h2 id="banner">Joven Mobile</h2>
<div class="main_menu">
<ul data-inset="true" data-role="listview">
<li><a href="EcioJven.html"><img src="themes/icons/news.png" alt="Information" class="ui-li-icon">Esen</a></li>
<li><a href="NeJoven.html"><img src="themes/icons/research.png" alt="Information" class="ui-li-icon">Laen</a></li>
<li><a href="photos.html"><img src="themes/icons/staff.png" alt="Information" class="ui-li-icon">Multimedia</a></li>
<li><a href="SajhrJoven.html"><img src="themes/icons/students.png" alt="Information" class="ui-li-icon">Sanen</a></li>
</ul>
</div>
</div>
<!--
<div data-role="footer">
<h4>Page Footer</h4>
</div>
-->
</div>
</body>
</html>
photos.html 看起来像:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Mobile Web App</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--<link href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" rel="stylesheet" type="text/css"/>-->
<link rel="stylesheet" href="themes/EspacioJoven.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile.structure-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<link rel="stylesheet" href="themes/custom.css" />
<!-- Needed from PhotoSwipe Plugin -->
<link href="photoSwipe/jquery-mobile.css" type="text/css" rel="stylesheet" />
<link href="photoSwipe/photoswipe.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="photoSwipe/klass.min.js"></script>
<script type="text/javascript" src="photoSwipe/code.photoswipe.jquery-3.0.5.min.js"></script>
<script type='text/javascript' src='photoSwipe/photoSwipeCall.js'></script>
<!-- Needed from PhotoSwipe Plugin -->
</head>
<body>
<div data-role="page" id="photos" data-theme="a" data-add-back-btn="true" data-back-btn-text="Back">
<div data-role="header" data-id="fixedNav" data-position="fixed">
<h1>Application Title</h1>
<a href="#" data-icon="back" data-rel="back" title="Go back">Back</a>
<div data-role="navbar">
<ul>
<li><a href="photos.html" class="ui-btn-active ui-state-persist">Photos</a></li>
<li><a href="videos.html">Videos</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /header -->
<div data-role="content">
<ul data-role="listview" data-inset="true" class="albums">
<!-- Here the albums are created through javascript (createAlbums.js) -->
</ul>
<button type="button" id="loadMoreAlbums">More Albums...</button>
</div><!-- /content -->
</div><!-- /page -->
<div id="fb-root"></div>
<script type='text/javascript' src='javascript/createAlbums3.js'></script>
</body>
</html>
如您所见,我最后调用了我的 javascript。任何想法为什么它从未被调用过?如果我刷新页面,这意味着运行 photos.html,它将正常加载。
实际上,我还查看了调试器中的“元素”表。当我在 index.html 页面中时,html 元素似乎都是正确的。当我过渡到 photos.html 页面时,通过查看元素表我发现它们没有改变!标题确实改变了,但其余部分保持不变,这真是不可思议?!这到底是怎么发生的?看起来是同一个页面,具有相同的 css 和 javascript 源,但应该不同!如您所见,我使用 photoSwipe javascript、css 等!只有当我重新加载页面时,元素才是正确的。请问有什么想法吗?我不知道这里发生了什么。
同样出于某种原因,我在从一页到另一页的转换过程中得到了 304 Status , Not Modified
。
最佳答案
这是因为当您导航到 jQuery Mobile 中的页面时,默认情况下它会尝试拉取 JQM 页面(data-role="page"
(如果没有数据- role='page' 然后它将通过 ajax 拉取 body
)) 并将其附加到当前页面的 DOM
,问题是它只会拉取 JQM 页面(或body
如果没有)并忽略它之外的所有内容(除了标题),这意味着您的 JavaScript 不会被调用。
当您刷新页面时,将进行正常的 HTTP 调用并加载整个页面,以便执行您的代码。
为了让您的 JavaScript 被调用,您需要在您的第一个页面上有相关的脚本,或者您可以将它与您的 JQM 页面包装器一起使用,然后它会被一起拉出。
<div data-role="page" id="photos" data-theme="a"
data-add-back-btn="true" data-back-btn-text="Back">
....
<script type='text/javascript' src='javascript/createAlbums3.js'></script>
</div><!-- /page -->
看看 following Q&A从官方文档获取更多详细信息。
关于通过 listview,jquery mobile 导航时,Javascript 不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18203750/
$.mobile.pageContainer 是指包含其他虚拟页面的元素。它设置为 .所以我认为它可以改变。实际上,某些 JQM 方法 (changePage) 允许您为页面指定非默认页面容器。 J
如何在移动设备上更改方向时触发事件。 调整大小 在 iPod Touch 上运行良好,但在使用 Opera mobile 作为浏览器的移动设备上运行良好。 有关如何在 Opera mobile 上触发
我想为我拥有的装有 Windows Mobile 2003 的设备开发一些应用程序,但我不想为此寻找 Visual Studio 2003 的副本。我想知道是否可以将 Mobile 6 SDK 用于此
我试图阻止 jQuery Mobile 在调用 changePage 时隐藏加载微调器。 程序流程是这样的,从点击一个链接开始,它的点击事件定义如下: $('body').delegate('.lib
我想为运行 Windows Mobile 5 的扫描仪开发应用程序。 MSDN 站点说要下载最新的 SDK(Windows Mobile 6 Professional SDK)。这会起作用还是我应该下
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我正在尝试使用 Jquery mobile 创建弹出菜单,通过单击按钮,它应该在不更改页面的情况下弹出菜单选项,类似于 jquery mobile 的选择菜单。在 JQM 中有没有办法做到这一点? 谢
在移动设备中,当我打开我的页面并选择一个输入框时,虚拟键盘打开,页面自动滚动以将输入框置于中心。 我不想要这个 Action 。 我搜索了很多答案,其中大多数建议在调整大小事件中手动调用以下 java
jQuery 移动列表中是否可以有多个拆分按钮? 我试过这样做: 1 但它不起作用。将链接包装在 中也不行.我做错了什么,
我想从我的 .js 文件中打开 .html 文件。所以我使用了 $.mobile.changePage("file.html")。在file.html 中有file.js。但是 file.js 在调用
我们有许多使用 Windows Mobile 6 的用户,需要应用较小的更改。例如。更新注册表设置。一种选择是使用我们的设备管理软件推送和执行可执行文件。 我希望这对熟悉 VBScript/JScri
我在PHP网站上有一个日期字段,并且我正在使用jQuery Mobile作为移动网站。 在移动浏览器(例如android上的firefox mobile)上浏览网站时,单击日期文本输入时,会出现日历对
我正在构建一个PhoneGap + JQuery Mobile应用程序,但似乎无法阻止它通过双击放大。我按照http://www.tricedesigns.com/2012/01/17/mobile-
随着 jQuery Mobile 1.3 的到来,.navigate()已添加功能。我听说这是更改页面的推荐方法,似乎他们解决了在页面之间传输数据的问题。 问题是,既然已经简化了,我该如何访问 cha
我想得到一个 input文本区域和 submit按钮附在它的右侧。 理想情况下,两者将使用 100% 的宽度并且并排放置。 我一直在尝试玩弄ui-grid-a和类似的选择,但一切都失败了。你可以看到一
我正在使用 jquery-mobile,我有这两个按钮: Pro: Reset 我希望它们并排显示(内联)。但我想不通。我做了this但它不起作用。你能帮我吗 ?这是我的 CSS:
我正在为 Windows Mobile 6.5 (Samsung Omnia II i8000) 开发 native 应用程序。进行一些更改后,我的应用程序在运行时挂起。 问题是我的应用程序也在启动期
有没有办法从周围和图标中删除背景光盘(圆圈)?我找到的光盘的唯一引用如下 background: rgba(0,0,0,.4) /*{global-ic
jQuery 移动版虽然在很多方面都很棒,但有时也令人沮丧。在这种情况下,我试图动态创建库中非常好的按钮之一。 基本上我想要做的是在输入字段中输入文本,当按下空格键时,它会创建一个带有文本的 jQue
我想在我的第 2 页上显示标题。使用以下内容是否有效: "> .... ? 最佳答案 这取决于你定义什么为“有效”
我是一名优秀的程序员,十分优秀!