Home  >  Article  >  Web Front-end  >  Implementation of page jump and loading external pages in jQuery mobile web development_jquery

Implementation of page jump and loading external pages in jQuery mobile web development_jquery

WBOY
WBOYOriginal
2016-05-16 15:27:221501browse

changePage() page jump

jQuery.mobile.changePage( to [, options ] )

To jump from one page to another, use the changePage method of the $.mobile object. But to use this method, you have to click a link or submit a form. This method has two parameters.

to: It is the first parameter, it is necessary and indispensable. Type: string or object.

String: Absolute or relative URL address. For example: ("about/us.html")

Object:
jquery selector object, such as: ($("#about")).
An array [from, to] that specifies two page references, used to jump to a known page. From is the currently visible page (or $.mobile.activePage).
Object to send form data, such as ({to: url, data: serialized form data, type: "get" or "post"}.

options: It is the second parameter and is optional. Type: Object

allowSamePageTransition (boolean, default: false)
By default, changePage() ignores requests to jump to an already active page. If this is set to true, it will be executed. Developers should note that some page transitions will assume that the source page and the target page in a request to jump to a page are different, so there will be no transition animation.

changeHash (boolean, default: true)
Determines whether the address bar hash should be updated.

data (string or object, default: undefined)
The data to be sent via ajax request is only available when the to parameter of changePage() is an address.

dataUrl (String, default: undefined)
The URL address of the browser address is updated when the page conversion is completed. If not specified, the data-url attribute value of the page is used.

pageContainer (jQuery selector, default: $.mobile.pageContainer) specifies the container that should contain the page.

reloadPage (boolean, default: false)
Force refresh of the page, even when the DOM element in the page container is ready. Only available when the to parameter of changePage() is an address.

reverse (boolean, default: false)
Set the direction of the page transition animation. When set to true, it will cause the transition in the opposite direction.

role (string, default: undefined)
Use the data-role value when displaying the page. By default this parameter is undefined, meaning it depends on the element's @data-role attribute.

showLoadMsg (Boolean value, default: true) Set whether to display loading information when loading external pages.

transition (String, default: $.mobile.defaultPageTransition) Transition when using the displayed page.

type (string, default: get)
Specify the method used when requesting the page ("get" or "post"). Only available when the to parameter of changePage() is an address.

//以slideup效果 跳转到 "about us" 页面

$.mobile.changePage("about/us.html", "slideup"); 
//以pop效果 跳转到 "confirm" 页面 并且在url hash里不记录其历史

$.mobile.changePage("../alerts/confirm.html", "pop", false, false); 
//跳转到 "search results" 页面,提交id为 "search"的表单数据

$.mobile.changePage({url:"searchresults.php" , type:"get" , data: $("form#search").serialize() }); 
//将页面url,类型,数据定义为变量来传递。

var pageData = { url: formresults.php, type: 'get', data:$('form#myform').serialize () };

$.mobile.changePage(pageData);
//使用changepage来加载第三个页面

var previousPage = $.mobile.activePage.data ('ui.prevPage');

$.mobile.changePage([previousPage, anotherPreviousPage], 'pop');


loadPage() loads external page

jQuery.mobile.loadPage( url [, options ] )

加载一个外部页面,附加其内容,并将其插入到DOM

url:是第一个参数。是必须的。类型:字符串或者对象。

options:第二个参数。是可选的。类型:对象。

allowSamePageTransition (default: false)
类型:布尔值
默认情况下,changepage()忽略请求改变当前页面。这个选项设置为true,允许请求执行。开发人员应该注意的一些网页过渡假设一个changepage请求设置FromPage、ToPage是不同的,所以他们可能不会如预期的动画。开发人员负责提供适当的过渡,或关闭这个特定的情况下。

changeHash (default: true)
类型:布尔值
如果地址栏中的哈希值应更新

data (default: undefined)
类型:数据或者字符串
要发送的数据与一个AJAX页面请求

loadMsgDelay (default: 50)
类型:数字
被迫延迟(毫秒)显示之前加载信息。这是为了让一个页面已经访问了被从缓存中取得没有加载信息的时间

pageContainer (default: $.mobile.pageContainer)
类型:jQuery选择器
指定要包含的页面元素

reloadPage (default: false)
类型:布尔值
强制刷新页面, 即使当页面容器中的dom元素已经准备好时,也强制刷新。只在changePage() 的 to 参数 是一个地址的时候可用。

role (default: undefined)
类型:字符串
显示页面的时候使用data-role值。默认情况下此参数为认:undefined,依赖于元素的@data-role属性。

showLoadMsg (default: true)
类型:布尔值
加载外部页面时,设定是否显示loading信息。

transition (default: $.mobile.defaultPageTransition)
类型:字符串
使用显示的页面时,过渡

type (default: "get")
类型:字符串
指定页面请求的时候使用的方法("get" 或者 "post")。只在changePage() 的 to 参数 是一个地址的时候可用。

加载一个外部页面,提高其内容,并将其插入到DOM。这种方法被称为内部的changepage()功能时,它的第一个参数是一个URL。这个函数不影响当前页面可以在后台加载页面。该函数返回一个对象,获取延期承诺在该页被增强,插入到文档中的解决。
加载“about/us.html”的页面到DOM

<!doctype html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>jQuery.mobile.loadPage demo</title>
 <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css">
 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 <!-- The script below can be omitted -->
 <script src="/resources/turnOffPushState.js"></script>
 <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
</head>
<body>
 
<div data-role="page">
 
 <div></div>
 
</div>
<script>
$.mobile.loadPage( "about/us.html" );
</script>
 
</body>
</html>

 

加载一个“searchresults.php”页,要发送的表单数据是“search”字符。

<!doctype html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>jQuery.mobile.loadPage demo</title>
 <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css">
 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 <!-- The script below can be omitted -->
 <script src="/resources/turnOffPushState.js"></script>
 <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
</head>
<body>
 
<div data-role="page">
 
 <div></div>
 
</div>
<script>
$.mobile.loadPage( "searchresults.php", {
 type: "post",
 data: $( "form#search" ).serialize()
});
</script>
 
</body>
</html>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn