创建< iframe>元素并使用jQuery将html内容附加到它 [英] Create an <iframe> element and append html content to it with jQuery

查看:101
本文介绍了创建< iframe>元素并使用jQuery将html内容附加到它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用jQuery创建< iframe> 元素,并在不使用 src 指定了属性?

Is it possible using jQuery to create an <iframe> element and append html content to it without having src attribute specified?

问题是我需要创建一个 iframe 并且我已经有了它的内容(我得到了)它作为AJAX响应)。不幸的是,我无法指定我从 src 属性获得响应的URL。我想做类似的事情:

The problem is I need to create an iframe and I already have its content (I get it as AJAX response). Unfortunately, I can't specify the URL I get response from as src attribute. I'd like to do something like:

$('<iframe id="someId"/>').append(response).appendTo("#someDiv");


推荐答案

试试这个:

$('<iframe id="someId"/>').appendTo('#someDiv')
                          .contents().find('body').append(response);

这篇关于创建&lt; iframe&gt;元素并使用jQuery将html内容附加到它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆