jQTouch 转到下一页时执行 javascript 代码
我一直在开发一个需要我动态更改内容的 iPhone 应用程序。我有以下代码:
<div id="home">
<div class="toolbar">
<a class="blueButton" href="javascript: void(0);" onClick="$('#logout').show();">Logout</a>
<h1>AllaccessMD</h1>
</div>
<h1>Home</h1>
<ul class="edgetoedge" id="ulHome"></ul>
</div>
当调用此页面时,我调用 javascript 函数:
function setupHome(){
if(localStorage.role == "Specialist"){
var homeUL = '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#ePresentations">My E-Presentation</a></li>'
+ '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#date">My Newsletter</a></li>'
+ '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#date">My Events</a></li>'
+ '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#date">Medical Partners</a></li>'
+ '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#date">Search</a></li>'
+ '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#date">Profile</a></li>';
$('#ulHome').html(homeUL);
} else {
var homeUL = '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#date">Medical Partners</a></li>'
+ '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#date">Search</a></li>'
+ '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#date">Profile</a></li>';
$('#ulHome').html(homeUL);
}
$('#ulHome li a').click(function(){
alert('I dont see this alert on a iPhone!');
if(this.href.search("#ePresentations") != 0) {
var idObject = getID(this.id);
setupEPresentation(idObject.id);
}
});
}
除了 $('#ulHome li a').click() 不起作用之外,这一切都工作正常。它在 Firefox 和 Chrome 上运行良好,但在 iPhone 上则不行。
我哪里做错了?或者有更好的方法来实现这个吗?
谢谢!
I have been working on an iPhone app that requires me to dynamically change the content. I have the following code:
<div id="home">
<div class="toolbar">
<a class="blueButton" href="javascript: void(0);" onClick="$('#logout').show();">Logout</a>
<h1>AllaccessMD</h1>
</div>
<h1>Home</h1>
<ul class="edgetoedge" id="ulHome"></ul>
</div>
When this page gets called I call the javascript function:
function setupHome(){
if(localStorage.role == "Specialist"){
var homeUL = '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#ePresentations">My E-Presentation</a></li>'
+ '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#date">My Newsletter</a></li>'
+ '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#date">My Events</a></li>'
+ '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#date">Medical Partners</a></li>'
+ '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#date">Search</a></li>'
+ '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#date">Profile</a></li>';
$('#ulHome').html(homeUL);
} else {
var homeUL = '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#date">Medical Partners</a></li>'
+ '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#date">Search</a></li>'
+ '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#date">Profile</a></li>';
$('#ulHome').html(homeUL);
}
$('#ulHome li a').click(function(){
alert('I dont see this alert on a iPhone!');
if(this.href.search("#ePresentations") != 0) {
var idObject = getID(this.id);
setupEPresentation(idObject.id);
}
});
}
This all works fine except the $('#ulHome li a').click() doesn't work. It works fine on Firefox and Chrome, but not on a iPhone.
Where did I go wrong? OR is there a better way to implement this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用点击而不是单击,自动更改页面功能也会覆盖您的链接,因为它们有一个 href 位置。另外,我不会将代码中的 javascript 与 javascript 中的事件混合在一起,所以
:
Use tap instead of click, also the auto change page function is going to override your links since they have an href location. Also I wouldn't mix javascript in the code with events in the javascript, so:
and