使用 js 插入一个页面的 php 结果以输入另一个页面的文本


Insert php result from one page to input text from another page with js

Page1 : test.php (在弹出窗口中打开)

<script type="text/javascript">
function addFiles(aFiles) {
if ($('#addfiles').length==0) $('#addfiles').html;
for (var i=0;i<aFiles.length;i++)   $("#addfiles").append(""+aFiles[i].file+"");
                      }
</script>
<?php
$result = "<div id='"addfiles'"></div>";    (everything works good here, i have only one result)
?>

页面2:结果.php(主页,已打开)

<input type="texta" name="texta" id="texta" value="<? echo $result; ?>"/>(我需要 value=" 在$result有一些结果而不刷新所有页面时自动更新$result。

谢谢

编辑:

function addFiles(aFiles) {
if ($('#addfiles').length==0) $('#addfiles').html;
for (var i=0;i<aFiles.length;i++) $("#addfiles").append(""+aFiles[0].file+"");
(window.opener.location = 'http://www.example.com/value='+aFiles[0].file+'');
self.close();   
}       

现在工作得很好。谢谢

<?php 
if($result) {
    echo '<script language="JavaScript">window.opener.location = "http://example.com/?value='.$result.'");self.close();</script>';
}
?>

然后让父窗口通过$_GET['value']获取存储在"value"中的值,并将其回显到输入字段的"value"属性中。

小心,您现在正在将整个<div>写入value="..."