IBM Worklight - Clicking a button to navigate to another HTML page doesn't work (multiple page application)

六眼飞鱼酱① 提交于 2019-12-11 10:29:26

问题


I'm trying to follow this guide. I reach a problem when i try to change the HTML file when the user clicks a button.

This is my script:

<script>
        window.$ = window.jQuery = WLJQ;
        $("#btnPromo").click(function(){
            $("#pagePort").load("pages/MainPage.html", function(){
                alert("loaded!");
            });
        });
    </script>

And this is my core HTML file (auto generated by Worklight):

<body onload="WL.Client.init({})" id="content" style="display: none;">
<!--application UI goes here-->
<div data-role="page" id="pagePort">
    <div id="header" align="center">
        <img src="images/logo.png">
    </div>

    <div data-role="content">
        <div>
            <input type="image" name="btnPromo" src="images/btnHotPromo.png" width="75%"/>
        </div>
        <div>
            <input type="image" name="btnMall" src="images/btnMall.png" width="75%"/>
        </div>
        <div>
            <input type="image" name="btnOutlet" src="images/btnOutlet.png" width="75%"/>
        </div>
        <div>
            <input type="image" name="btnAbout" src="images/btnAbout.png" width="75%"/>
        </div>
    </div>
</div>

My goal is to change the #pagePort to MainPage.html every time the user clicks on #btnPromo.


回答1:


The answer is i forgot to add the $(function(){}); at the start of the code, so the code should be :

$(function(){
        $("#btnPromo").click(function(){
            $("#pagePort").load("pages/MainPage.html", function(){
                alert("loaded!");
            });
        });
});

And everything will be OK :D



来源:https://stackoverflow.com/questions/17185260/ibm-worklight-clicking-a-button-to-navigate-to-another-html-page-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!