【问题标题】:How to have the popup dialog disappear after some time?如何让弹出对话框在一段时间后消失?
【发布时间】:2013-05-14 21:30:22
【问题描述】:

我如何使用 jQuery + jQuery Mobile。有一个弹出对话框在一段时间后消失。 这个我在某种程度上写的作品。它会在一段时间后消失。但是,当我单击按钮再次激活它时,它不起作用,除非我再次刷新页面。

JavaScript

<script type="text/javascript">
     $(document).on('pageinit', function(e) {
        $('#postnote').click(function() {
            $('#dialog').popup('open', {history: false}).delay(500).fadeOut('slow').hide();
        });
    });
</script>

页面

<div data-role="page" id="addnote">
    <div id="dialog" data-role="popup" data-transition="fade">
        <div data-role="header"><h1>Note posted</h1></div>
    </div>
    <div data-role="header" data-theme="a">
        <h1>Add Note</h1>
    </div>
    <div data-role="content" data-theme="b">
        <textarea id="note" rows="40" name="note"></textarea>
        <a href="#" id="postnote" data-role="button" data-transition="fade" data-theme="b">Post</a>
        <a href="#" data-rel="back" data-role="button" data-transition="slidefade" data-theme="a" data-direction="reverse">Back</a>
    </div><!-- /content -->
</div><!-- /page -->

【问题讨论】:

    标签: jquery jquery-mobile setinterval jquery-mobile-popup


    【解决方案1】:

    你可以这样做。

    $(document).on('popupafteropen', '.ui-popup', function() {
     setTimeout(function () {
      $(this).popup('close');
     }, 5000);
    });
    

    【讨论】:

      【解决方案2】:

      工作示例:http://jsfiddle.net/Gajotres/6M9ES/

      HTML:

      <div data-role="page" id="addnote">
          <div data-role="header" data-theme="a">
              <h1>Add Note</h1>
          </div>
          <div data-role="content" data-theme="b">
              <div id="dialog" data-role="popup" data-transition="fade">
                  <div data-role="header"><h1>Note posted</h1></div>
              </div>                
              <textarea id="note" rows="40" name="note"></textarea>
              <a href="#" id="postnote" data-role="button" data-transition="fade" data-theme="b">Post</a>
              <a href="#" data-rel="back" data-role="button" data-transition="slidefade" data-theme="a" data-direction="reverse">Back</a>
          </div><!-- /content -->
      </div><!-- /page -->  
      

      Javascript:

      $(document).on('pageinit', '#addnote', function(){ 
          $('#postnote').click(function() {
              var interval = setInterval(function(){
                  $('#dialog').popup('open', {history: false});//.delay(500).fadeOut('slow');
                  var intervalClose = setInterval(function(){    
                      $('#dialog').popup('close');
                      clearInterval(intervalClose);
                  },1000);
                  clearInterval(interval);
              },1);           
          });      
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-10
        • 1970-01-01
        • 2019-08-18
        • 1970-01-01
        • 2013-05-17
        相关资源
        最近更新 更多