widdy 2012-07-03 16:47
浏览 289
已采纳

如何自动生成iframe的内容

我自己写了一个xslt转换jQuery的api文件(xml),现在就是有一个问题,里面的demo不知道怎么写了。如下面的图片,这是jQuery官方文档的demo实现方式,是一个iframe,我就在想怎么把xml文件里面那个节点内容放进这个iframe里呢,它的所有iframe的src都一样的,肯定不是生成一个html文件的.我不知道怎么弄了,谢谢!
[img]http://dl.iteye.com/upload/attachment/0070/2720/fdbf2e7d-6b8a-3dfe-b277-314bb5dbcbca.jpg[/img]

[img]http://dl.iteye.com/upload/attachment/0070/2722/ce39b2c4-18de-300c-a769-bc1f7336dced.jpg[/img]

XML的代码
[code="xml"]

Remove the two white spaces at the start and at the end of the string.
<![CDATA[
var str = " lots of spaces before and after ";
$("#original").html("Original String: '" + str + "'");
$("#trimmed").html("$.trim()'ed: '" + $.trim(str) + "'");
]]>

<![CDATA[



]]>
[/code]

  • 写回答

2条回答 默认 最新

  • kjah_1 2012-07-04 16:48
    关注

    只要拿到iframe的document,然后open write close就行了

    给你个示例代码

    [code="html"]
    window.onload=function(){
    document.body.innerHTML+='';
    var fwin=document.getElementById("ifm").contentWindow;
    var fdoc=fwin.document;

        var script='window.onload=function(){document.body.innerHTML="hello!"}';
        fdoc.open(); 
        fdoc.writeln('<html><head><style>p{margin:0px;padding:0px;}body{margin:0px;padding:0px;font:16/18px Arial;}</style></head><body><script>'+script+'</script></body></html>'); 
        fdoc.close();
    }
    

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答