0

iframeがその親関数に変数を送信する際に問題が発生しました。topPHP.phpは、問題を引き起こしている関数と、pdfドキュメントの投稿をloadPHP.phpに送信するフォームであるentryPHP.phpをロードするiframeを持っている私の親であり、データベースにpdfをアップロードして関数を呼び出します。親topPHP.phpの。runon文でごめんなさい。私が得る結果は次のとおりです。

when topPHP.php loads the div topDiv reads "No Control"
I choose a file in the iframe (src = entryPHP.php) and hit submit
loadPHP.php is called and the file is upload to the database perfectly
In the Javascript/Jquery the alert "before the function" is called and works
After that the div topDiv still reads "No Control" and the second alert "after the function" is not called

どんな助けでも大歓迎です。

topPHP:

<script type="text/javascript" src="../jQuery.js"></script>
<script type="text/javascript">

$( document ).ready(function() {
num = 1;

function changeDiv(num){
if(num==1)
{
$("#topDiv").val("top control");
}
if(num==2)
{
$("#topDiv").val("bottom control");
}
}
}
</script>

<iframe id="iframe_display" src="entryPHP.php" width="400" height="100">
</iframe>

<div id="topDiv">
no control
</div>

entryPHP:

<div id="uploadPDF">
<form enctype="multipart/form-data" method="POST" action="loadPHP.php">
<table width="300" height="25" border="1">
//this table sends a pdf file as a post to loadPHP.psh
</table>
</form>

loadPHP:

<?php
//this uploads the pdf file to the database
?>

<script type="text/javascript" src="../jQuery.js"></script>
<script type="text/javascript">
$( document ).ready(function() {

$(window).load(function(){

});
alert("before the function");
parent.changeDiv(2);
alert("after the function");

});
</script>

ありがとう

4

1 に答える 1

1

changeDiv()jQuery関数内で関数を定義したため、そのスコープ内にのみ存在し、オブジェクトready()の一部としてアクセスすることはできません。parent

この問題を修正するには、次のように関数をtopPHPページのグローバルスコープに移動します。

<script type="text/javascript">
function changeDiv(num){
    if(num==1)
    {
        $("#topDiv").val("top control");
    }
    if(num==2)
    {
        $("#topDiv").val("bottom control");
    }
}
$( document ).ready(function() {
    changeDiv(1);
}
</script>
于 2013-03-25T17:06:01.327 に答える