Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 删除div内容并添加iframe_Javascript_Jquery_Html_Jquery Mobile - Fatal编程技术网

Javascript 删除div内容并添加iframe

Javascript 删除div内容并添加iframe,javascript,jquery,html,jquery-mobile,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_conn

在我的应用程序中,我想删除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 函数cif(){

$(“#内容”).remove();
$(“#目录”).html(“”);
}

当我删除div内容并且在创建iframe之后它不会显示,我需要在单击按钮删除内容之后,在内容创建iframe之后,如果您删除“内容”,它就会消失。。。此后无法更改它的html(),因为它已消失。你可能想跳过第一行。

如果你删除了“内容”,它就不见了。。。此后无法更改它的html(),因为它已消失。您可能希望完全跳过第一行。

$(“#contents”).remove()
删除整个

您正在查找
$('#contents”).empty()
,它将删除
$('#contents”)。remove()
删除整个

您正在查找
$(“#contents”).empty()
,它将删除
.html()
调用
.empty()
(如果需要)中的所有内容,因此不需要调用
.html()
调用
.empty()
(如果需要),因此不需要这样做
$("#contents").remove();
$("#contents").html('<iframe src="http://google.com" style="height: 100%; width: 100%"></iframe>');