Javascript iframe src页面添加动态输入不起作用

我想在 div 内容 javascript 中添加输入,但它不添加


HTML:


<button onclick="Addcompntn();" class="btn btn-success">Add</button>

<iframe class="embed-responsive-item" src="index.html" allowfullscreen id="if1"></iframe>

脚本:


function Addcompntn() {

    var framedeki = document.getElementById('if1').contentWindow.document; 

    $('example').append('<div id="innerdiv" style="color:white;"></div>');

}

索引.html


<div id="example" style="z-index:2"> //dynamic data will come here </div>


杨魅力
浏览 116回答 1
1回答

烙印99

尝试将元素添加到 iframe 文档主体:function Addcompntn() {&nbsp; &nbsp; var framedeki = document.getElementById('if1').contentWindow.document;&nbsp; &nbsp;&nbsp; &nbsp; var div = document.createElement("div");&nbsp; &nbsp; div.id = 'innerdiv';&nbsp; &nbsp; div.style.color = 'white';&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; framedeki.getElementById('example').append(div);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript