2014-09-05 71 views
1

我有一個第一頁「main.php」,帶有一個打開彈出窗口「pop.php」的按鈕,其中可以檢查不同選項。在選擇不同的選項並按下「ok」後,是否有可能使用js或jquery將「pop.php」表單的結果傳遞給「main.php」中的字段而不重新加載? 感謝您的回答!將變量從頁面傳遞到使用js或jquery的已打開頁面

回答

1

是。有了JavaScript,使用jQuery就變得簡單了。

的jQuery上pop.php

<script>  
jQuery(function($){ 
    // when your popup form submits this will be called 
    $('form').submit(function(event){ 
     // this stops the form from submitting 
     event.preventDefault(); 
     // this sends the form data to a JS function on main.php 
     window.parent.popup_data_process($(this).serialize()); 
     // this closes this window because we don't need it anymore 
     window.close(); 
    }); 
}); 
</script> 

JS上main.php

<script> 
// this function is the receiver which will process your form data 
function popup_data_process(serializedData) 
{ 
    // this displays the data to your console 
    console.log(serializedData); 
} 
</script> 
+0

謝謝!它幫助很大! – Snipchain 2014-09-05 20:07:50

0

您可以使用window.parent屬性訪問父窗口。並調用任何全局級別功能,您希望

var popUp = window.open("pop.php"); 

內pop.php

if(!!window.parent){ 
    window.parent.someFunction(dataToPadd); 
} 
相關問題