简体   繁体   English

转到下一页时,jQTouch执行JavaScript代码

[英]jQTouch excute javascript code when going to next page

I have been working on an iPhone app that requires me to dynamically change the content. 我一直在开发一个iPhone应用程序,该应用程序要求我动态更改内容。 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: 调用此页面后,我将调用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);
    }
});

} }

This all works fine except the $('#ulHome li a').click() doesn't work. 除$('#ulHome li a')。click()不起作用外,所有其他方法都工作正常。 It works fine on Firefox and Chrome, but not on a iPhone. 它可以在Firefox和Chrome上正常运行,但不能在iPhone上运行。

Where did I go wrong? 我哪里做错了? OR is there a better way to implement this? 还是有更好的方法来实现这一目标?

Thanks! 谢谢!

Use tap instead of click, also the auto change page function is going to override your links since they have an href location. 使用点击而不是单击,由于链接具有href位置,因此自动更改页面功能还将覆盖您的链接。 Also I wouldn't mix javascript in the code with events in the javascript, so: 另外,我不会将代码中的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>

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();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM