jquerymobile-包括.js和.html [英] jquerymobile - include .js and .html

查看:102
本文介绍了jquerymobile-包括.js和.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在使用多个HTML页面来显示内容,并且每个页面都有自己的.js文件.当我调用html页面时,.js文件也包括在内.在.js中,我正在使用$('div').live('pageshow',function(){}).我正在从.js(using $.mobile.changePage("htmlpage"))调用html文件.

In my application,I am using more than html page for displaying the content and each page have own .js file. When I call the html page then .js file also included. In the .js,I am using $('div').live('pageshow',function(){}). I am calling the html file from the .js(using $.mobile.changePage("htmlpage")).

我的问题:考虑,我有两个html文件.在one.js中调用second.html文件.当我显示second.html时,那一次one.js再次被重新加载.我收到警报"one.js",然后是"second.js"

My problem: consider, I have two html files. second.html file is called with in the one.js. when I show the second.html, that time one.js is reload again. I am getting the alert "one.js" then "second.js"

one.html

<!DOCTYPE html> 
<html> 
  <head> 
    <title>Page Title</title> 
    <link rel="stylesheet" href="jquery.mobile-1.0a2.min.css" />
    <script src="jquery-1.4.3.min.js"></script>
    <script src="jquery.mobile-1.0a2.min.js"></script> 
    <script src="Scripts/one.js"></script>
  </head> 
  <body>         
    <div data-role="page">
    </div>
  </body>
</html>

Second.html

<!DOCTYPE html> 
<html> 
  <head> 
    <title>Sample </title> 
    <link rel="stylesheet" href="../jquery.mobile-1.0a2.min.css" />
    <script src="../jquery-1.4.3.min.js"></script>
    <script src="../jquery.mobile-1.0a2.min.js"></script>
    <script type="text/javascript" src="Scripts/second.js"></script>
  </head> 
  <body>
    <div data-role="page">   
      <div data-role="button" id="link" >Second</div>
    </div><!-- /page -->
  </body>
</html>

one.js

$('div').live('pageshow',function()
{     
   alert("one.js");
   //AJAX Calling 
   //success result than call the second.html 
   $.mobile.changePage("second.html");                   
});

second.js

$('div').live('pageshow',function(){
{     
   alert('second.js');  
   //AJAX Calling 
   //success result than call the second.html 
   $.mobile.changePage("third.html");                   
});

注意:当我显示当年的html.html时,将重新加载以下文件(one.js,second.js,third,js和fourth.js.但是我仅需要fourth.js).我尝试使用$ .document.ready(function(){});但是那个时候.js没有打电话.

Note : When I show forth.html that time the following files are reload(one.js,second.js,third,js and fourth.js. But I need fourth.js alone). I tried to use the $.document.ready(function(){}); but that time .js did not call.

推荐答案

pageshow事件绑定了每次加载页面时都会触发的JavaScript函数.加载第二个页面时,您正在创建实际上不需要创建的另一个pageshow函数.

The pageshow event binds JavaScript functions that fire each time the page loads. When you load the second page, you're creating another pageshow function that you actually don't need to create.

仅在以下情况下定义一次,这才有助于解决您的问题:

This should help solve your problem, if and only if you define this once:

 $('div').live('pageshow',function(event, ui){
    alert('This page was just hidden: '+ ui.prevPage);
 });

 $('div').live('pagehide',function(event, ui){
    alert('This page was just shown: '+ ui.nextPage);
 });

当您转换页面时,这将提醒您刚刚显示的页面和刚刚隐藏的页面.

When you transition pages, this will alert you with what page was just shown, and what page was just hidden.

丰富的资源:
http://jquerymobile.com/demos/1.0a2/#docs/api /events.html

Great resource:
http://jquerymobile.com/demos/1.0a2/#docs/api/events.html

http://forum.jquery.com/topic/mobile-events-documentation

这篇关于jquerymobile-包括.js和.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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