删除div内容并添加iframe

时间:2012-05-26 12:21:26

标签: javascript jquery html jquery-mobile

在我的应用程序中,我想删除div内容并添加iframe,这是我的代码

的index.html

<div data-role="page">
    <div data-role="header" >
    <div data-role="content" id="contents">
        <a href="#" data-role="button" onclick="cif()"><img src="images/zo_connect.png"></a>
        </div>

    </div><!-- /content -->
</div><!-- /page -->

default.js function cif(){

$("#contents").remove();
$("#contents").html('<iframe src="http://google.com" style="height: 100%; width: 100%"></iframe>');

}

当我删除div内容并在之后创建iframe它没有显示时,我需要在单击按钮后删除内容,然后在该内容中创建iframe

2 个答案:

答案 0 :(得分:3)

好吧,如果删除“内容”,它就会消失......之后你不能改变它的html(),因为它已经消失了。您可能希望完全跳过第一行。

答案 1 :(得分:3)

$('#contents").remove()删除了整个<div id='contents'></div>

您正在寻找$('#contents").empty(),这将删除<div id='contents'>

中的所有内容
相关问题