首页 新闻 赞助 找找看

(操作iframe子页面的内容)想在head里动态添加script

0
悬赏园豆:15 [已解决问题] 解决于 2014-12-28 16:20

document.getElementById('iframe').onload=function(){

var iframe=$(document.getElementById("iframe").contentWindow.document); 

$(iframe).find("head").append($("<script type='text/javascript' src='js/move.js'></script>"));//这样写没反正能得到object ,但给他append就没反应了

//$(iframe).body.html("sdfsdfds") 这样写也没问题可以修改到,$(iframe).find("head").append却没有效

}

小鬼文的主页 小鬼文 | 初学一级 | 园豆:108
提问于:2014-12-27 20:58
< >
分享
最佳答案
0

这样,不用jquery:

document.getElementsByTagName('head')[0].innerHTML=document.getElementsByTagName('head')[0].innerHTML+"js脚本";

有人这么解释

All of jQuery's insertion methods use a domManip function internally to clean/process elements before and after they are inserted into the DOM. One of the things the domManip function does is pull out any script elements about to be inserted and run them through an "evalScript routine" rather than inject them with the rest of the DOM fragment. It inserts the scripts separately, evaluates them, and then removes them from the DOM.

说是插不进,可以执行一次,但是最后会被移除

收获园豆:15
arg | 小虾三级 |园豆:1047 | 2014-12-28 12:58

   可以了,谢谢哈

小鬼文 | 园豆:108 (初学一级) | 2014-12-28 16:20
其他回答(2)
0

你把js拿到body下面执行试一试

隔壁老王来了 | 园豆:99 (初学一级) | 2014-12-27 23:42
0

.append($("<script type='text/javascript' src='js/move.js'></script>"));要写成

.append("<script type='text/javascript' src='js/move.js'></script>");

不谢!

Slark.NET | 园豆:692 (小虾三级) | 2014-12-27 23:43

没用呢

支持(0) 反对(0) 小鬼文 | 园豆:108 (初学一级) | 2014-12-28 12:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册