jQuery Mobile Multiple Dialog Boxes in One Dialog

前端 未结 1 490
予麋鹿
予麋鹿 2021-01-07 06:47

I have searched and have not found example of doing this. I want to be able to have a dialog box open for jQM and have it where there is a step by step process that takes pl

相关标签:
1条回答
  • 2021-01-07 07:30

    Here is an example, using .show() and .hide(). The trick here is to create several divs, and then show/hide them.

    Working Demo

    Markup

    <div data-role="dialog" id="dialog">
     <div data-role="header" data-theme="d">
      <h1>Dialog</h1>
     </div>
    
    <!-- First Page -->
     <div data-role="content" id="page1">
      <h3>Page 1</h3>
      <p>Text for #page1</p>
      <div class="ui-grid-a">
       <div class="ui-block-a">
        <a href="#" data-role="button" data-theme="b" class="prev">Previous</a>
       </div>
       <div class="ui-block-b">
        <a href="#" data-role="button" data-theme="e" class="next">Next</a>
       </div>
      </div>
     </div>
    
    <!-- Second Page -->
    
    <div data-role="content" id="page2">
      <h3>Page 2</h3>
      <p>Text for #page2</p>
      <div class="ui-grid-a">
       <div class="ui-block-a">
        <a href="#" data-role="button" data-theme="b" class="prev">Previous</a>
       </div>
       <div class="ui-block-b">
        <a href="#" data-role="button" data-theme="e" class="next">Next</a>
       </div>
      </div>
     </div>
    
    <!-- Third Page -->
    <div data-role="content" id="page3">
      <h3>Page 3</h3>
      <p>Text for #page3</p>
      <div class="ui-grid-a">
       <div class="ui-block-a">
        <a href="#" data-role="button" data-theme="b" class="prev">Previous</a>
       </div>
       <div class="ui-block-b">
        <a href="#" data-role="button" data-theme="e" class="next">Next</a>
       </div>
      </div>
     </div>
    
    </div>
    

    Code

    // hide previous button, #page2 and #page3 once opened
    $('#dialog').find('#page1 a.prev').hide();
    $('#page2, #page3').hide();
    
    // #page1 to #page2
    $('#page1 a.next').on('click', function () {
     $('#page1').hide();
     $('#page2').show();
    });
    
    // #page2 to #page3
    $('#page2 a.next').on('click', function () {
     $('#page1, #page2').hide();
     $('#page3').show();
     $('#dialog').find('#page3 a.next').hide();
    });
    
    // #page2 to #page1
    $('#page2 a.prev').on('click', function () {
     $('#page2').hide();
     $('#page1').show();
    });
    
    // #page3 to #page2
    $('#page3 a.prev').on('click', function () {
     $('#page2, #page3').hide();
     $('#page2').show();
    });
    
    0 讨论(0)
提交回复
热议问题