jQTouch 转到下一页时执行 javascript 代码

发布于 2024-09-17 19:50:13 字数 2186 浏览 5 评论 0原文

我一直在开发一个需要我动态更改内容的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开半夏魅人心 2024-09-24 19:50:13

使用点击而不是单击,自动更改页面功能也会覆盖您的链接,因为它们有一个 href 位置。另外,我不会将代码中的 javascript 与 javascript 中的事件混合在一起,所以

   <div id="home">
     <div class="toolbar">
        <a id="logoutButton" class="blueButton" href="#">Logout</a>
        <h1>AllaccessMD</h1>
     </div>
   <h1>Home</h1>
   <ul class="edgetoedge" id="ulHome"></ul>
   </div>

function setupHome(){
if(localStorage.role == "Specialist"){
    var homeUL = '<li class="arrow"><a class="Presentation" id="s,' + localStorage.userID + '" href="#">My E-Presentation</a></li>'
            + '<li class="arrow"><a id="s,' + localStorage.userID + '" data="#">My Newsletter</a></li>'
            + '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#">My Events</a></li>'
            + '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#">Medical Partners</a></li>'
            + '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#">Search</a></li>'
            + '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#">Profile</a></li>';
    $('#ulHome').html(homeUL);
} else {
    var homeUL = '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#">Medical Partners</a></li>'
            + '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#">Search</a></li>'
            + '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#">Profile</a></li>';
    $('#ulHome').html(homeUL);
}

$('#ulHome li a').tap(function(){
    alert('I dont see this alert on a iPhone!');
    if(this.hasClass("Presentations") ) {
        var idObject = getID(this.id);
        setupEPresentation(idObject.id);
    }
});

$('#logoutButton').tap(function() { 
   $('#logout').show();
});

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:

   <div id="home">
     <div class="toolbar">
        <a id="logoutButton" class="blueButton" href="#">Logout</a>
        <h1>AllaccessMD</h1>
     </div>
   <h1>Home</h1>
   <ul class="edgetoedge" id="ulHome"></ul>
   </div>

and

function setupHome(){
if(localStorage.role == "Specialist"){
    var homeUL = '<li class="arrow"><a class="Presentation" id="s,' + localStorage.userID + '" href="#">My E-Presentation</a></li>'
            + '<li class="arrow"><a id="s,' + localStorage.userID + '" data="#">My Newsletter</a></li>'
            + '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#">My Events</a></li>'
            + '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#">Medical Partners</a></li>'
            + '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#">Search</a></li>'
            + '<li class="arrow"><a id="s,' + localStorage.userID + '" href="#">Profile</a></li>';
    $('#ulHome').html(homeUL);
} else {
    var homeUL = '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#">Medical Partners</a></li>'
            + '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#">Search</a></li>'
            + '<li class="arrow"><a id="m,' + localStorage.userID + '" href="#">Profile</a></li>';
    $('#ulHome').html(homeUL);
}

$('#ulHome li a').tap(function(){
    alert('I dont see this alert on a iPhone!');
    if(this.hasClass("Presentations") ) {
        var idObject = getID(this.id);
        setupEPresentation(idObject.id);
    }
});

$('#logoutButton').tap(function() { 
   $('#logout').show();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文