javascript - How to link Internal Pages in Jquery mobile? - Stack Overflow

What to do if i want to link two internal pages on the click of a button using jquery or javascript...

What to do if i want to link two internal pages on the click of a button using jquery or javascript... i can do it using <a href=#nextPage"> in HTML but i want a script to do it! what i am doing right now is:

<!-- first page-->
<div data-role="page" id="firstPage">
<div data-role="header"> 
<h1>Test page</h1>
</div>
<div data-role="content">
<p>this page will link internal pages using # </p>
<a href="#nextPage" data-role="button">change to next page</a>
</div>
</div>

<!-- second page-->
<div data-role="page" id="nextPage">
<div data-role="header"> 
<h1>Test page 2 </h1>
</div>
<div data-role="content">
<p>this page will  appear after you click the button on first page. </p>
</div>
</div>

this is doing good, but what i need is a script to link them. as in my app i need to change the page on click of button only after certain conditions met. but i dont know how to do it...

-----------Edit------------ I found out a way window.location.href="#nextPage" this is how its done. Thanks all for your effort..

What to do if i want to link two internal pages on the click of a button using jquery or javascript... i can do it using <a href=#nextPage"> in HTML but i want a script to do it! what i am doing right now is:

<!-- first page-->
<div data-role="page" id="firstPage">
<div data-role="header"> 
<h1>Test page</h1>
</div>
<div data-role="content">
<p>this page will link internal pages using # </p>
<a href="#nextPage" data-role="button">change to next page</a>
</div>
</div>

<!-- second page-->
<div data-role="page" id="nextPage">
<div data-role="header"> 
<h1>Test page 2 </h1>
</div>
<div data-role="content">
<p>this page will  appear after you click the button on first page. </p>
</div>
</div>

this is doing good, but what i need is a script to link them. as in my app i need to change the page on click of button only after certain conditions met. but i dont know how to do it...

-----------Edit------------ I found out a way window.location.href="#nextPage" this is how its done. Thanks all for your effort..

Share Improve this question edited Jul 23, 2012 at 6:14 priyankirk asked Jul 23, 2012 at 4:04 priyankirkpriyankirk 451 gold badge4 silver badges9 bronze badges 3
  • You can add onclick event, or even better (?), you can attach the .click event. – nhahtdh Commented Jul 23, 2012 at 4:07
  • i am doing it in my real app. but how to change the page???? – priyankirk Commented Jul 23, 2012 at 4:09
  • Use $.mobile.changePage - see my answer. – nhahtdh Commented Jul 23, 2012 at 4:18
Add a ment  | 

2 Answers 2

Reset to default 2

You can add onclick handler to the a tag:

JS

function navigate() {
    if (condition) {
        $.mobile.changePage("#nextPage");
    }
}

HTML

<a href="#" onclick="navigate()" data-role="button">change to next page</a>

OR you can do this:

JS

$(document).ready(function() {
    $(".nav-nextPage").click(function() {
        if (condition) {
            $.mobile.changePage("#nextPage");
        }
    });
});

HTML

<a href="#" class="nav-nextPage" data-role="button">change to next page</a>

jQuery Mobile, Anatomy of a Page

Scroll down to Local, internal linked "pages"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745036054a4607523.html

相关推荐

  • javascript - How to link Internal Pages in Jquery mobile? - Stack Overflow

    What to do if i want to link two internal pages on the click of a button using jquery or javascript...

    1天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信