在JavaScript不会加载到DOM jQuery中移动 [英] as in Javascript is not loaded into dom in jquery mobile

查看:93
本文介绍了在JavaScript不会加载到DOM jQuery中移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个page1.html,有一个链接在它是这样的:

 < A HREF =page2.html>第2页< / A>
 

一个部分 page2.html 是这样的:

 < HTML>
< HEAD>
< /头>
<身体GT;
< D​​IV数据角色=页面>
< / DIV>
&所述;脚本的src =file1.js>&所述; /脚本>
&所述;脚本的src =file.js>&所述; /脚本>
< /身体GT;
< / HTML>
 

和也这样的:

 < HTML>
< HEAD>
< /头>
<身体GT;
< D​​IV数据角色=页面>
< / DIV>
< D​​IV数据角色=页面>
&所述;脚本的src =file1.js>&所述; /脚本>
&所述;脚本的src =file.js>&所述; /脚本>
< / DIV>
< /身体GT;
< / HTML>
 

这两个 JS 文件落实 page2.html 一些功能,但导航到 page2.html 通过 page1.html 这两个文件无法正常工作,但与数据AJAX =假它的工作原理。 哪里不对。应该在哪里剧本放在哪里?我需要的默认 AJAX 的更平滑的过渡。

解决方案

更新

  

根据您的更新问题,您不可以混合的单页型号的用的多页型号的。当加载的 page2.html 的第数据角色=页面键,只有第一个被加载,否则就是忽略了。

例:

index.html的(第一个页面加载) - 内的所有标签< HTML> 加载到DOM阿贾克斯是否启用或禁用

 < HTML>
  < HEAD>
    &所述;! -  JS,CSS等。 - >
  < /头>
  <身体GT;
    <! - 网页 - >
  < /身体GT;
< / HTML>
 

page2.html - 所有的标签都被忽略,除了第一个数据角色=页面及其内容,当Ajax是启用

 <! - 在头库被忽略了 - >
< HEAD>
  &所述;! -  JS,CSS等。 - >
< /头>
<身体GT;

<! - 只有第一页加载 - >
  < D​​IV数据角色=页面>
   <! -  JS  - >
  < / DIV>
<! - 下一个页面被忽略了 - >
  < D​​IV数据角色=页面>
  < / DIV>
< /身体GT;
 

在使用的单页型号的和Ajax是启用,你必须把JS库/ code代表的外部的页面中< D​​IV数据角色=页面>

 < D​​IV数据角色=页面>
  &所述;脚本的src =file1.js>&所述; /脚本>
  &所述;脚本的src =file.js>&所述; /脚本>
< / DIV>
 

jQuery Mobile的负载的外部的通过Ajax的页面,只加载第一个< D​​IV数据角色=页面>在 <身体,而忽略任何其他标​​记出方的的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不会加载到DOM jQuery中移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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