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

从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>
  • 写回答

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");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制