【发布时间】:2012-12-05 18:47:17
【问题描述】:
我正在使用 JQuery Mobile 1.2 和 php 开发 Web 应用程序。在个人资料页面上,我有一个弹出窗口要求用户确认注销。我想要做的是通过点击事件拦截该按钮以通过 ajax 请求处理注销。
我的所有项目页面中都包含一个 custom.js 文件。该应用程序在帐户页面中加载。我知道它正在加载并在 ajax 导航中工作。 当我将此代码包含在 custom.js 中时:
$("#perfil").live('pageshow',function(event){
alert('This page was just enhanced by jQuery Mobile!');
});
我在显示个人资料页面时收到警报。问题是点击功能。
当我包含这个时:
$("#perfil").live('pageshow',function(event){
alert('This page was just enhanced by jQuery Mobile!');
$('#logoutButton').click(function(){
$('#output').html('Logging Out...');
$.get("api/logout",function(data){
if(data.success) {
window.location = "index"
}
else{
$('#output').html('Logout failed. Try again');
}
}, "json");
});
});
行为很奇怪。当我从主页导航到个人资料页面时,我收到了警报。但是按钮没有反应。但是,当我刷新(或最初从配置文件页面加载应用程序)时,按钮行为正确并运行 javascript 注销功能。
这里是html按钮的代码:
<a id="logoutButton" data-role="button" data-icon="check"
data-inline="true" data-theme="e">Si, finalizar.</a>
【问题讨论】:
-
我为格式道歉...似乎无法正确阅读。
-
为了将来参考,back-tics 用于格式化内联代码,用于格式化代码块,您将其缩进四个空格,或者您可以通过突出显示您的代码并单击格式代码按钮{}。
标签: javascript html jquery-mobile