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 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办