dtvgo28624
2016-01-08 07:12
浏览 40
已采纳

从iframe调用函数

I am uploading files using a hidden iframe as a target...from inside this iframe I want to run a function that's on my main page.

In my target iframe.php I have

<script>

upload_completed(<?php echo $numerolinha ?>); 
    </script>

but I get from firebug:

ReferenceError: loading_linha_21 is not defined
parent.upload_completed();</script>

If I run upload_completed(loading_linha_21); on my main page it runs ok so I'm guessing the command to run the function on the parent page isn't working... help!

I also tried :

window.top.upload_completed(<?php echo $numerolinha ?>); 

window.upload_completed(<?php echo $numerolinha ?>);

my functions :

 <script >
 function upload_started(id){

  $(id).css("display","block");
 }
 function upload_completed(id){
 $(id).css("display","none");
 }


 </script>

图片转代码服务由CSDN问答提供 功能建议

我使用隐藏的iframe作为目标上传文件...从这个iframe里面我想运行一个函数 这是在我的主页上。

在我的目标 iframe.php 中我有

 &lt; script&gt;  
 
upload_completed(&lt;?php echo $ numerolinha?&gt;);  
&lt; / script&gt; 
   
 
 

但是我来自firebug:

  ReferenceError:loading_linha_21未定义 
parent.upload_completed();&lt; / script&gt; 
   
 
 

如果我在我的主页上运行 upload_completed(loading_linha_21); ,它会运行 好吧所以我猜测在父页面上运行该功能的命令不起作用...帮助!

我也试过了:

  window.top.upload_completed(&lt;?php echo $ numerolinha?&gt;);  
 
window.upload_completed(&lt;?php echo $ numerolinha?&gt;); 
   
 
 

我的函数:

  &lt; script&gt; 
 function upload_started(id){
 
 $(id).css(“display”,“block”); 
} 
 function upload_completed(id){
 $  (id).css(“display”,“none”); 
} 
 
 
&lt; / script&gt; 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dtdd25012 2016-01-08 09:29
    已采纳

    The best guess i can give you is that the jQuery function requires the id to be #name_of_id, so when you call the function from the iframe like so:

    parent.upload_completed('#<?php echo $numerolinha ?>');
    

    or you can change your function to do this:

    function upload_started(id){
        $( '#' + id).css("display","block");
    }
    
    function upload_completed( id ) {
        $( '#' + id ).css("display","none");
    }
    
    点赞 评论
  • dongyuruan2957 2016-01-08 07:18

    Put a ' inside function like below :

    <script>
    upload_completed('<?php echo $numerolinha ?>'); 
    </script>
    
    点赞 评论

相关推荐 更多相似问题