我有第一页“ main.php”,其中有一个按钮,它会打开一个弹出式窗口“ pop.php”,在其中可以检查其他选项。选择不同的选项后,按“确定”时,是否可以使用js或jquery将“ pop.php”表单的结果传递给“ main.php”中的字段,而无需重新加载它?感谢您的回答!
是的。使用JavaScript可以实现,而使用jQuery则更容易。
jQuery on 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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句