简体   繁体   English

无法在JQuery Mobile中以编程方式显示Dialog

[英]Can't Get Dialog to show programmatically in JQuery Mobile

I'm trying to get a div with data-type 'dialog' to display in JQuery Mobile, fired by a Javascript event. 我正在尝试使用数据类型“对话框”来获取一个div,以便在JQuery Mobile中显示,由Javascript事件触发。 The button click in the example below is purely to fire the event. 下面示例中的按钮单击纯粹是为了触发事件。

<head>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            //$.mobile.changePage('#addCatForm');

            $('#createEvent').click (function () {
                console.log('Prove event fired');

                $.mobile.changePage('#addCatForm', {
                    transition: 'pop',
                    changeHash: false,
                    role: 'dialog'
                });
            });

        });
    </script>
</head>
<body>
    <div data-role="page" id="mainPage">
        <button id="createEvent">Create Event</button>
        <div data-role="dialog" id="addCatForm" data-theme="c">
            <p>here is some text</p>
            <div data-role="content">
                <input type="text" id="catText" data-theme="c"/>
                <input data-role="button" data-mini="true" data-theme="b" data-inline="true" type="submit" id="addCat" value="Add Category">

                <button data-role="button" data-mini="true" data-theme="c" data-inline="true" id="canCat">Cancel</button>
            </div>
        </div>
    </div>    
</body>

The console.log output correctly fires, but nothing I can do seems to get the dialog to display. console.log输出正确触发,但我无能为力似乎要显示对话框。

Any help appreciated. 任何帮助赞赏。

Thank you, 谢谢,

Working example: http://jsfiddle.net/Gajotres/Jx9xM/ 工作示例: http//jsfiddle.net/Gajotres/Jx9xM/

$(document).ready(function() {    
    $('#createEvent').click (function () {
        console.log('Prove event fired');

        $.mobile.changePage('#addCatForm', {
            transition: 'pop',
            changeHash: true,
            role: 'dialog'
        });
    });
});

Dialog must be on a same level as a page and not a part of the page. 对话框必须与页面位于同一级别,而不是页面的一部分。 I this case I have moved dialog outside of a page. 在这种情况下,我在一个页面之外移动了对话框。

Your structure should look like this, data-role=dialog outside data-role=page . 您的结构应该如下所示, data-role=dialogdata-role=page

<!-- Page -->
<div data-role="page" id="mainPage">
 <button id="createEvent">Create Event</button>
</div> 
<!-- /Page -->

<!-- Dialog -->
<div data-role="dialog" id="addCatForm" data-theme="c">
 <p>here is some text</p>
 <div data-role="content">
  <input type="text" id="catText" data-theme="c"/>
  <input data-role="button" data-mini="true" data-theme="b" data-inline="true" type="submit" id="addCat" value="Add Category">
  <button data-role="button" data-mini="true" data-theme="c" data-inline="true" id="canCat">Cancel</button>
  </div>
 </div>
 <!-- /Dialog -->

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

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