简体   繁体   English

使用jQuery Mobile隐藏和显示div

[英]Hide and show div with jquery mobile

Well, this is the first time i'm using jquery mobile. 好吧,这是我第一次使用jquery mobile。 I'm trying to make a single page mobile app and i have two divs like follows: 我正在尝试制作一个单页移动应用程序,我有两个div,如下所示:

<div data-role="page" id="divStart">
        <div data-role="content">
            <a id='btnShowSignUp' data-role="button" href='#' onclick="ShowSignUp();">Sign Up</a>
            <a id='btnShowSignUp' data-role="button" href='#' onclick="ShowLogin();">Login</a>
        </div>
</div>
<div data-role="page" id="divSignUp" style='display: none'>
        <div data-role="content">
            <form id='formSignUp' method='POST'>
                <div data-role="fieldcontain">
                    <label for="name">Name</label>
                    <input name="name" id="name" type="text">
                    <label for="email">E-mail</label>
                    <input name="email" id="email" type="text">
                    <label for="pass">Pass</label>
                    <input name="pass" id="pass" type="password">
                </div>
                <a data-role="button" href="#" onclick='SignUp();'>Save</a>
            </form>
        </div>
</div>

When i click the button 'btnShowSignUp', i call the function: 当我单击按钮“ btnShowSignUp”时,我调用该函数:

function ShowSignUp(){
    $('#divStart').hide();
    $('#divSignUp').show();
}

My problem: when i click the button, the 'divStart' disappear and the 'divSignUp' shows up, but it misses some of its jquery mobile attributes. 我的问题:当我单击按钮时,“ divStart”消失,并且显示“ divSignUp”,但是它错过了它的jquery移动属性。 Why is this happening? 为什么会这样呢?

Thanks! 谢谢!

You aren't following JQM's navigation API. 您没有遵循JQM的导航API。 The JQM framework manages the showing and hiding of your various "pages", along with applying any transition between them: JQM框架管理各种“页面”的显示和隐藏,以及在它们之间应用任何过渡:

 function ShowSignUp(){
   $.mobile.changePage( "#divStart" );
 }

With a fancy transition: 花哨的过渡:

 $.mobile.changePage( "#divStart", { transition: "pop" });

If you try doing JQM's job for it, you're likely going to end up with unanticipated results. 如果您尝试为此完成JQM的工作,那么最终结果可能会出乎意料。

http://api.jquerymobile.com/jQuery.mobile.changePage/ http://api.jquerymobile.com/jQuery.mobile.changePage/

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

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