javascript - 使用 jquery mobile 隐藏和显示 div

标签 javascript css jquery-mobile html show-hide

好吧,这是我第一次使用 jquery mobile。 我正在尝试制作一个单页移动应用程序,我有两个 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>

当我点击“btnShowSignUp”按钮时,我调用函数:

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

我的问题:当我单击该按钮时,“divStart”消失而“divSignUp”出现,但它遗漏了它的一些 jquery 移动属性。为什么会这样?

谢谢!

最佳答案

您没有遵循 JQM 的导航 API。 JQM 框架管理各种“页面”的显示和隐藏,以及应用它们之间的任何转换:

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

花哨的过渡:

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

如果您尝试为此完成 JQM 的工作,您很可能会得到意想不到的结果。

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

关于javascript - 使用 jquery mobile 隐藏和显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20164117/

相关文章:

javascript - 在预编码的 HTML 中显示 Javascript 数组?

javascript - 如何覆盖 ajax=false 以便它切换到加载的 dom 页面(如果存在)

html - 如何使下拉菜单正确运行?

javascript - jQuery clone div 每次点击

jquery-mobile - jQuery Mobile与AngularJs页面导航

javascript - 使用一些翻译事件的代码(包括代码)在移动设备上拖放,但正常事件不起作用

javascript - 在 C# 中使用 AJAX 绑定(bind) gridview 时报告“未定义”

javascript - Angular Js ng-controller 未填充该值

javascript - 错误 : Cannot find a differ supporting object '[object Object]' of type 'object' . NgFor 只支持绑定(bind)到 Iterables

javascript - 如何在ajax成功中中断执行并显示错误?