2012-07-23 51 views
0

如果我想链接使用jquery或javascript的按钮的点击两个内部页面怎么办... 我可以在HTML中使用<a href=#nextPage">但我想要一个脚本来做到这一点!我现在正在做的是:如何链接Jquery mobile中的内部页面?

<!-- 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> 

这是做得很好,但我需要的是脚本来链接它们。因为在我的应用程序中,我只需要在某些条件满足的情况下点击按钮来更改页面。但我不知道该怎么办...

-----------编辑------------ 我找到了一个方法 window.location。 href =“#nextPage” 这是如何完成的。 感谢所有为你的努力..

+0

您可以添加'onclick'事件,甚至更好的(?),你可以附加'.click'事件。 – nhahtdh 2012-07-23 04:07:42

+0

我正在做我的真实应用程序。但如何更改页面? – priyankirk 2012-07-23 04:09:32

+0

使用'$ .mobile.changePage' - 查看我的答案。 – nhahtdh 2012-07-23 04:18:33

回答

1

jQuery Mobile的,Anatomy of a Page

向下滚动到本地,内部链接 “页”

+0

这就是我现在正在做的。 我需要一个脚本... somthing like window.location and other stuff .. – priyankirk 2012-07-23 04:14:05

3

您可以添加onclick处理到a标签:

JS

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

HTML

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

或者你可以这样做:

JS

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

^h TML

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

$ .mobile.changePage(“#nextPage”); 不工作! 什么都没有发生! – priyankirk 2012-07-23 04:26:54

+0

@priyankirk:如果你包含jQuery Mobile,它应该可以工作。我使用控制台进行了测试,现在我正在研究类似的代码。 – nhahtdh 2012-07-23 04:29:34

+0

好的idk,在模拟器中它不工作,但在浏览器中它是! 反正我找到另一个出路 window.location.href =“#nextPage”; – priyankirk 2012-07-23 06:13:13

相关问题