我是 jquery 移动框架的新手。根据我的观察,我无法在文档的第一页上触发 pagebeforeshow 事件
有人遇到过同样的问题吗?请建议我触发事件的步骤或任何其他替代方案
最佳答案
在演示中,当 pagebeforeshow
处理程序被触发时,您将看到警报。
剩下的代码会说清楚,希望有帮助,
代码
$(document).bind('mobileinit', function() {
alert('mobileinit');
});
$(function() {
var selector = ':jqmData(role=page)';
$('body').on('pageinit', selector, function(e, data) {
// initialize page
var $page = $(this);
alert('init ' + $page.attr('id'));
}).on('pagebeforeshow', selector, function(e, data) {
// showpage
var $page = $(this);
alert('show Page before Show Stuff == > ' + $page.attr('id'));
});
$('#page1').on('pageinit', function(e, data) {
// setup handler
var $page = $(this);
$page.find('.colorchanger').click(function() {
var $content = $page.find('.ui-content'),
isBodyC = $content.hasClass('ui-body-c');
$content.toggleClass('ui-body-c', !isBodyC).toggleClass('ui-body-e', isBodyC);
});
});
});
关于javascript - jquery mobile pageshow 事件未在首页上触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11240408/