我有以下页面布局
<div id="userscore" >test</div>
<iframe name="frameContent" id="frameContent" width="100%" height="100%" frameborder="0" />
Run Code Online (Sandbox Code Playgroud)
iFrame动态获取其内容,包括其javascript.
当我尝试从iFrame中访问userscore时
console.log(window.parent.document.getElementById('user-score'));
Run Code Online (Sandbox Code Playgroud)
我进入控制台
<div id="userscore" >test</div>
Run Code Online (Sandbox Code Playgroud)
当我尝试使用时
window.parent.document.getElementById('user-score').html('Change the content');
Run Code Online (Sandbox Code Playgroud)
我明白了
Object [object HTMLDivElement] has no method 'html'
Run Code Online (Sandbox Code Playgroud)
有没有解决的办法?或者任何人都可以了解正在发生的事情.
DOM元素没有方法.html().该方法是jQuery等JavaScript库中经常出现的扩展.
使用纯JavaScript时,.innerHTML如果要更改元素的内容,则必须设置属性.
window.parent.document.getElementById('user-score').innerHTML = "New content";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
949 次 |
| 最近记录: |