【发布时间】:2015-11-09 22:27:57
【问题描述】:
有谁知道为什么会这样——也就是说,添加了属性——在 Chrome 中,而不是在 Firefox 中?
this.wrapper.appendChild(this.ifr = document.createElement('iframe'));
this.ifr_doc = this.ifr.contentDocument || this.ifr.document;
this.ifr_doc.documentElement.querySelector('body').setAttribute('foo', 'bar'); //GRR...
没有错误;它只是在 Chrome 中,在检查器中,属性会显示,而在 Firefox (v 41.0.2) 中则不会。
(this.wrapper 是一个容纳 iframe 的容器)
【问题讨论】:
-
检查你的
this.ifr_doc.documentElement.querySelector('body')元素,它是否在ff中定义? -
是的,我查过了。
标签: javascript iframe document