2013-08-18 112 views
0

我有我的视图页面上的按钮,只要其获得点击,会出现一个弹出式模态...现在我想关闭该模式......我怎样才能关闭模式弹出窗口的jQuery

这里是我的代码

function openSirenModal() { 
var timeout; 
var progress; 
var status; 

$.modal({ 
    contentAlign: 'center', 
    width: 240, 
    title: 'Loading', 
    content: '<div style="line-height: 25px; padding: 0 0 10px"><span id="modal-status">Contacting to the device...</span><br><span id="modal-progress">0%</span></div>', 
    buttons: {}, 
    scrolling: false, 
    actions: { 
     'Cancel': { 
      color: 'red', 
      click: function (win) { 
       win.closeModal(); 
      } 
     } 
    }, 
    onOpen: function() { 
     // Progress bar 
     var progress = $('#modal-progress').progress(100, { 
      size: 200, 
      style: 'large', 
      barClasses: ['anthracite-gradient', 'glossy'], 
      stripes: true, 
      darkStripes: false, 
      showValue: false 
     }), 

      // Loading state 
      loaded = 0, 

      // Window 
      win = $(this), 

      // Status text 
      status = $('#modal-status'), 

      // Function to simulate loading 
      simulateLoading = function() { 




      }; 

     // Start 
     //timeout = setTimeout(simulateLoading, 2500); 
    }, 


    onClose: function() { 
     // Stop simulated loading if needed 
     clearTimeout(timeout); 
    } 


}); 

var siren = "siren"; 
$.ajax({ 
    type: "POST", 
    data: { 
     value: siren 
    }, 
    url: "http://localhost/siren/siren/", 

    success: function (data) { 
     alert(data); 
     if (data == 1) { 

      var auto_refresh = setInterval(
       function() { 
        $.get('siren/sirenjson', function (datas) { 

         if (datas == 1) { 

          $('#modal-progress').hideProgressStripes().changeProgressBarColor('green-gradient'); 
          $('#modal-status').text('success!'); 
          setTimeout(function() { 
           clearInterval(auto_refresh); 
           win.closeModal();//here i want to close the popup modal 
          }, 1500); 


         } 
        }); 

       }, 1000); 





     } else { 

     } 

     //clearTimeout(timeout); 
    }, 
    error: function() { 

     alert("error"); 
     progress.hideProgressStripes().changeProgressBarColor('red-gradient'); 
     setTimeout(function() { 
      win.closeModal(); 
     }, 1500); 
     status.text('error!'); 
    } 
}); 

}; 

我写代码win.closeModal();但它不工作,因为我不能访问取胜变量setInterval..i不知道我怎样才能访问它

+0

你想使用closeModal(); ...或者你也关闭通过增加接近股利情态 –

+0

我只是想关闭关闭模态..如果我不使用设置间隔,然后它的作品,否则它不会 – hellosheikh

+0

以及我只是想关闭模式..如果我没有指定时间间隔,那么我可以关闭它..但在间隔时间它不工作 – hellosheikh

回答

0
<div id="modal">Modal text <br /><button type='button' class='close'>CLOSE</button></div> 

$('.close').on('click', function(){ 
     $.modal.close(); 
     $('#modal, #open_modal').toggle(); 
    }); 

试试这个,如果你可以跳过closeModal();

JSFIDDLE TRIAL

+0

我不想点击任何关闭模式..我只想在成功消息出现后自动关闭模式... – hellosheikh

+0

http://jsbin.com/ofakab/尝试用计时器bcoz如何才能知道它是否成功 –

+0

好吧,我没有太多的经验,在JavaScript ..所以我想只是使用这种模式..以及我提交其他代码,在哪种模式是关闭罚款...我定制代码 – hellosheikh