bootstrap的modal提示框怎么实现自动关闭

发布时间: 2015/5/15 14:40:08

jquery ui 太丑陋了,现在换成bootstrap modal,请问大大如何在表单正确提交后自动关闭模态框?

<script>
                var myIntegral = 0;
                $(document).ready(function(){
                   $(".link").click(function(){
                       var id = $(this).attr('rel');
                       if(is_login){
                           $("#modal").dialog({
                               width:500,
                               height:300,
                               modal: true,
                               buttons:{
                                   '确定':function(){
                                       var data = $("#div form").serialize();
                                       $.ajax({
                                           url:'url&id='+id,
                                           data:data,
                                           type:'POST',
                                           dataType:'json',
                                           success:function(data){
                                               if(data.ret == 0) {
                                                   alert(data.message);
                                                   $("#modal").dialog('close');
                                               }else{
                                                   alert(data.message);
                                               }
                                           }
                                       });

                                   },
                                   '取消':function(){
                                       $(this).dialog('close');
                                   }
                               }
                           });                     
                       }else{
                            alert('需要登录后操作');
                            location.href ='login.php';
                       }

                   });
</script>

修改后

    <script>
    $(document).ready(function() {
      $(".link").click(function() {
        var id = $(this).attr('rel');
        if (is_signin) {
          $("#modal .modal-body > form").attr("action", "url&id=" + id);
          $("#modal").modal();
        } else {
          alert('需要登录后操作');
          location.href = 'login.php'
        }
      });
    });
    </script>


解决方法 1:

setTimeout(function(){$("#modal").modal("hide")},2000);


赞助商