gpt4 book ai didi

javascript - jquery pageinit 没有触发

转载 作者:数据小太阳 更新时间:2023-10-29 06:12:57 27 4
gpt4 key购买 nike

我有 2 个页面,我使用 swipeleft 和 swiperight 事件(来回)链接,但是当我滑动到另一个页面时,jquery 不会触发 pageinit 事件,我只剩下页眉和页脚。我应该使用 changePage 事件还是应该使用 loadPage 事件?我知道在其他版本的 jquerymobile 中有一个错误,其中 pageinit 事件没有触发,但我已经在使用 RC1,它已经解决了它,但事件仍然没有触发。是什么阻止它开火?提前致谢。

代码如下:

      <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>esports</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.css" />
<link rel="stylesheet" href="jquery.zrssfeed.css" />
</script>

<style>


</style>
</head>
<body>
<!-- index -->
<div data-role="page" id="index">
<div data-role="header">
<h1>esports times</h1>
</div>
<!--/header-->
<div data-role="content" id="content">
<div id="currentFeed">teamliquid. &nbsp; skgamin</div>
<ul id="rssFeed" data-role="listview">
</ul>
</div>
</div>

</body>
</html>

<!-- load javscripts here-->
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.js"> </script>
<script src="jquery.zrssfeed.js"></script>
<script>
$('#index').bind("pageinit", (function () {
$('#rssFeed').rssfeed('http://feeds.reuters.com/reuters/oddlyEnoughNews', {
limit: 10,
date: false,
});
}));

$('#index').bind("swipeleft", function () {
$.mobile.changePage("teamliquid.html", "slide", true, false);
});
</script>

<!-- /javascript-->

最佳答案

更改页面就是您要找的。加载页面只是将其加载到 dom 中,因此您可以在实际显示页面之前进行操作。

绑定(bind)到页面初始化时,请确保使用唯一 ID 绑定(bind)页面初始化事件。他们不能同时拥有 id="#index"。还要确保将页面初始化绑定(bind)到每个页面。您的代码只会为 #index 页面而不是 teamliquid.html 触发 pageinit。

<head></head> 中使用以下内容您的文件:

$(document).on('pageinit','#index', function(){
$('#rssFeed').rssfeed('http://feeds.reuters.com/reuters/oddlyEnoughNews', {
limit: 10,
date: false,
});
});
$(document).on('pageinit','#otherpage', function(){
... This would be for the other page you are referring to....
});
$(document).on('swipeleft','#index', function(){
$.mobile.changePage("teamliquid.html", { transition: "slide" });
});
$(document).on('swiperight','#otherpage', function(){
$.mobile.changePage("index.html", { transition: "slide" });
});

或者为每个页面获取 pageinit for fire

$(document).on('pageinit','[data-role=page]', function(){
....ground breaking code...
});

从 jquery 1.7 开始,bind、live 和 delegate 都使用 .on() 方法。这是为 JQM 绑定(bind) pageinit 的推荐方法。您还可以做一些很酷的事情,例如将“#index”替换为“[data-role=page]”,让您的代码在每个页面上都触发。这是一个 JSfiddle,证明这确实有效。 http://jsfiddle.net/codaniel/cEWpy/2/

关于javascript - jquery pageinit 没有触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9883459/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com