2011-05-04 99 views
1

您好我有一个问题,当我的脚本完成处理时使用jquery覆盖失败关闭。jquery覆盖不会关闭

我所做的只是显示一个非常简单的表单,将提交的值在后台处理并添加到页面中。一旦完成,覆盖图应该关闭,但是它只是停留在那里,并且直到我进行整页刷新时才会去。

我的jQuery代码看起来是这样的:

function employmenthistory(){ 

    $(document).ready(function(){ 

     /** 
     * Modal Dialog Boxes Setup 
     */ 
     var triggers = $(".modalInput").overlay({ 

      // some mask tweaks suitable for modal dialogs 
      mask: { 
       color: '#ebecff', 
       loadSpeed: 200, 
       opacity: 0.7 
      }, 

      closeOnClick: false 
     }); 

     /* User Input Prompt Modal Box */ 
     $("#employmentprompt form").submit(function(e) { 

      // get user input 
      var name = $("#name", this).val(); 
      var role = $('#role', this).val(); 
      var title = $("#title", this).val(); 

      //we need to know how many elements already exist 
      var elementCount = $('li.note').length; 

      //update server with information about this employment 
      $.ajax({ 
       url: '/addempl/', 
       type : 'post', 
       data : "name=" + name + "&role=" + role + "&title=" + title + "&ec=" + elementCount, 
       dataType: "json", 
       success : function(msg){ 

        //confirm the event was successful 
        if(msg.status == 'success'){ 

         var item = msg.data; 

         //we now add to the ul for elements 
         $('ul.listing').append(item); 

        }else{ 

         //failed to process so display error 
         $('div.message error').html('<p>We were unable to add your employment history</p><p>Please try again</p>'); 
        } 
       }, 
       error : function(err){ 

        //failed to call server 
        $('div.message error').html('<p>We were unable to add your employment history</p><p>Please try again</p>'); 
       } 
      }); 

      // close the overlay 
      triggers.eq(0).overlay().close(); 

      // do not submit the form 
      return e.preventDefault(); 
     }); 
    }); 



} 

这段代码的所有方面工作天晴,当我到达

triggers.eq(0).overlay().close(); 

与形式覆盖在它仍然在页面上。只有一个modelInput元素和窗体可以调用,所以我不知道为什么这是失败的。

所有我所做的就是按照这可以在这里找到了例子:

http://flowplayer.org/tools/demos/overlay/modal-dialog.html

任何帮助,这将受到欢迎。

谢谢。

回答

1

我认为你需要在你的覆盖命令中使用api参数。我没有看到他们的榜样,但我记得那是过去的问题。

var triggers = $(".modalInput").overlay({ 

     // some mask tweaks suitable for modal dialogs 
     mask: { 
      color: '#ebecff', 
      loadSpeed: 200, 
      opacity: 0.7 
     }, 

     closeOnClick: false, 
     api: true 
    }); 

更新

这里是示出从另一模态的打开/关闭以及开口一个模态一个Working Demo。希望能帮助到你。

这是我目前使用的代码......导致整个页面刷新/提交表单的

var currentModal; 

function openModal(divName){ 
    closeModal(); 
    if ($('#' + divName).length>0){ 
     currentModal=$('#'+divName).overlay({ 
      mask: {color: '#000000'},  
      top:'0px', 
      api: true   
     }).load(); 
    } 
}  
function closeModal(){ 
    if (currentModal){ 
     if (currentModal.isOpened){ 
      currentModal.close(); 
     } 
    } 
} 
+0

黯然。 – 2011-05-04 20:52:16

+0

请参阅我的更新与工作演示。 – Dutchie432 2011-05-05 12:52:52