因为在 Javascript 中未加载到 jquery mobile 中的 dom [英] as in Javascript is not loaded into dom in jquery mobile

查看:13
本文介绍了因为在 Javascript 中未加载到 jquery mobile 中的 dom的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 page1.html,里面有一个这样的链接:

PAGE2

一部分page2.html是这样的:

<头><身体><div data-role="页面">

<script src="file1.js"></script><script src="file.js"></script>

还有这个:

<头><身体><div data-role="页面">

<div data-role="页面"><script src="file1.js"></script><script src="file.js"></script>

这两个 js 文件在 page2.html 上实现了一些功能,但是当通过 page1.html 导航到 page2.html 这两个文件不起作用,但是当使用 data-ajax="false" 时它会起作用.怎么了.scripts 应该放在哪里?我需要默认的 ajax 以实现更平滑的过渡.

解决方案

更新

<块引用>

根据您更新的问题,您不能混合单页模型多页模型.当你加载 page2.html 第一个 data-role="page 并且只加载第一个.其他任何东西都被忽略了.

示例:

index.html(第一页加载) - 中的所有标签都被加载到 DOM 中,无论 Ajax 是启用还是禁用.

<头><!-- JS、CSS 等.--><身体><!-- 页面-->

page2.html - 当 Ajax 启用 时,除了 FIRST data-role="page" 及其内容之外,所有标签都被忽略.

<头><!-- JS、CSS 等.--><身体><!-- 仅加载第一页--><div data-role=页面"><!-- JS-->

<!-- 下一页被忽略了--><div data-role=页面">

当使用单页模型并且启用Ajax时,您必须将外部页面的JS库/代码放在中<div data-role="page">.

<script src="file1.js"></script><script src="file.js"></script>

jQuery Mobile 通过 Ajax 加载外部页面,它只加载

并忽略 page div 之外的任何其他标签.

I have a page1.html that has a link in it like this:

<a href="page2.html">PAGE2</a>

A part page2.html is like this:

<html>
<head>
</head>
<body>
<div data-role="page">
</div>
<script src="file1.js"></script>
<script src="file.js"></script>
</body>
</html>

And also this:

<html>
<head>
</head>
<body>
<div data-role="page">
</div>
<div data-role="page">
<script src="file1.js"></script>
<script src="file.js"></script>
</div>
</body>
</html>

These two js files implement some functionality on page2.html, but when navigating to page2.html via page1.html these two files wont work, but when done with data-ajax="false" it works. What is wrong. Where should the scripts be placed? I need default ajax for smoother transitions.

解决方案

Update

As per your updated question, you can't mix Single Page Model with Multi-Page Model. When you load page2.html first data-role="page and ONLY first one is loaded. Anything else is neglected.

Example:

index.html (first page loaded) - All tags within <html> are loaded into DOM whether Ajax is enabled or disabled.

<html>
  <head>
    <!-- JS, CSS, etc.. -->
  </head>
  <body>
    <!-- pages -->
  </body>
</html>

page2.html - All tags are neglected except for FIRST data-role="page" and its' content, when Ajax is enabled.

<!-- libraries in head are neglected -->
<head>
  <!-- JS, CSS, etc.. -->
</head>
<body>

<!-- ONLY first page is loaded -->
  <div data-role="page">
   <!-- JS -->
  </div>
<!-- next pages are neglected -->
  <div data-role="page">
  </div>
</body>

When using Single Page Model and Ajax is enabled, you have to place JS libraries/code for the external page inside <div data-role="page">.

<div data-role="page">
  <script src="file1.js"></script>
  <script src="file.js"></script>
</div>

jQuery Mobile loads external pages via Ajax, it loads ONLY first <div data-role="page"> in <body and neglects any other tags out side page div.

这篇关于因为在 Javascript 中未加载到 jquery mobile 中的 dom的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆