[英]Can I define "document" as a variable in Javascript?
在我的应用程序中,有时我想将在 querySelector 中使用的“文档”定义为“tinymce.get('steps_html').contentAreaContainer.childNodes[0].contentWindow.document”。 其他时候,我希望“文档”具有通常的含义。
有没有办法可以将“文档”设置为变量? 我尝试了以下方法,但都没有返回元素:
定义文件:
document = tinymce.get('steps_html').contentAreaContainer.childNodes[0].contentWindow.document;
document.querySelector(myElement) // Returns nothing
定义前缀:
prefix = tinymce.get('steps_html').contentAreaContainer.childNodes[0].contentWindow;
prefix.document.querySelector(myElement); //Returns nothing
将前缀定义为文本:
prefix = "tinymce.get('steps_html').contentAreaContainer.childNodes[0].contentWindow;
prefix.document.querySelector(myElement)"; //Returns nothing
只有tinymce.get('steps_html').contentAreaContainer.childNodes[0].contentWindow.document.querySelector(myElement)
返回一个元素。
Have you tried window.orig_document = window.document window.document = tinymce.get('steps_html').contentAreaContainer.childNodes[0].contentWindow.document window.document = window.document.orig_document
我找到了自己的答案。 我会发布它以防其他人看到这篇文章。
首先,找到你的 TinyMCE 编辑器 iframe
var iframe = document.querySelector("#myDiv .tox-editor-container .tox-edit-area iframe");
然后获取它的内容
var iframe_content = iframe.contentDocument;
然后你可以执行你的查询
var frame_li = iframe_content.querySelectorAll("#tinymce li");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.