2013-10-19 193 views
0

我正在使用Fancybox觸發搜索表單彈出窗口並且表單使用Javascript驗證來檢查並提交。我遇到的問題是我無法使Fancybox屏幕關閉然後運行該功能。下面是我使用的時刻代碼:提交表單並關閉Fancybox,Javascript

<form id="searchForm" method="post" action="<?php echo $search; ?>.php?type=rad" onsubmit="javascript:parent.jQuery.fancybox.close();"> 

$('#enterButton').click(function() 
     { 
     if(searchok == 1) 
     {   
      $('.searchValidation').addClass("sending"); 
      $("#searchForm").submit(); 
     } 
     else 
     { 
     $('.searchValidation').addClass("validationError"); 
     } 
     return false; 
     }); 

我怎樣才能獲得的fancybox窗口關閉上提交(),但仍有效地運行在父窗口的形式功能?

回答

2

假設#enterButtonsubmit按鈕,你最好調用

parent.jQuery.fancybox.close(); 

驗證函數內。我建議是這樣的:

$('#enterButton').click(function() 
     { 
     if(searchok == 1) 
     {   
      $('.searchValidation').addClass("sending"); 
      $("#searchForm").submit(); 
      parent.jQuery.fancybox.close(); 
     } 
     else 
     { 
     $('.searchValidation').addClass("validationError"); 
     } 
     return false; 
     }); 

然而parent.jQuery.fancybox.close();需要只有當你是一個iframe內使用它來使用。你可以用jQuery.fancybox.close();

取代它下面是一個參考,你可以檢查:parent.jQuery.fancybox.close(); from within Fancybox only closes Fancybox once

+1

謝謝,但這並沒有爲我工作。解決方案來自於簡單地使用_parent作爲表單的目標:'

。php?type = name」target =「_ parent 「>' – user2737457

+0

啊有趣,謝謝你的更新。 –

+0

謝謝你,user2737457! –