将多个代码镜像脚本应用于一个iframe
Applying multiple codemirror scripts to one iframe
我已经在我的网站上安装了Codemirror,我几乎已经把它拿到了我想要的地方。我可以用html编写代码并在iframe中预览它,但我希望能够将CSS文本区域和Javascript文本区域应用于同一个iframe???
有人知道怎么做吗?
只需加载两种模式,并为不同的CodeMirror实例提供不同的mode
选项。
这是一个对我有用的想法
<script>
var delay;
// HTML MODE
var html = CodeMirror.fromTextArea(document.getElementById("html"), {
lineNumbers: true,
lineWrapping: true,
mode: 'text/html'
});
html.on("change", function() {
clearTimeout(delay);
delay = setTimeout(updatePreview, 300);
});
// CSS MODE
var css = CodeMirror.fromTextArea(document.getElementById("css"), {
lineNumbers: true,
lineWrapping: true,
mode: 'text/css'
});
css.on("change", function() {
clearTimeout(delay);
delay = setTimeout(updatePreview, 300);
});
// Javascript MODE
var js = CodeMirror.fromTextArea(document.getElementById("js"), {
lineNumbers: true,
lineWrapping: true,
mode: 'text/javascript'
});
js.on("change", function() {
clearTimeout(delay);
delay = setTimeout(updatePreview, 300);
});
function updatePreview() {
var previewFrame = document.getElementById('preview');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
// Preview
preview.open();
preview.write('<style type="text/css">' + css.getValue() + '</style>');
preview.write(html.getValue());
preview.write(js.getValue());
preview.close();
}
setTimeout(updatePreview, 300);
</script>
希望有帮助
相关文章:
- 将一个iframe覆盖在另一个ifame上
- 从一个iframe到另一个ifame的过帐表单-IE
- 我如何才能包含一个iframe视频,这样它就不会't负载
- 从另一个 Iframe 刷新父 Iframe
- 一个iframe随机失败到XHR
- 我正在尝试创建一个iframe,它在单击按钮时会发生更改
- 从另一个iframe更改ElementById值的Javascript
- insertBefore() 一个 iframe jquery 问题
- 我能用BeautifulSoup在javascript后面得到一个iframe吗?
- 一个 iframe 上的按钮以显示另一个 iframe
- 如何将一个 iframe 的 html 内容复制到另一个 iframe(包括 CSS)
- 并排显示一个表、一个 iframe 和一个表
- Jquery的eq(0),“.first-child”,first()如果它是一个iframe,则不会抓住第一个孩子
- Facebook评论插件在iframe中加载一个iframe,导致宽度不响应
- 重复iframe:将头部和身体从一个iframe复制到另一个ifame
- 当用户点击facebook共享缩略图时,我可以加载一个iframe吗
- 在另一个iframe中为一个ifame加载函数
- 如何在iframe中欺骗一个iframe页面加载非
- 我可以在 dijit 编辑器中放置一个 iframe 吗?
- 当我使用另一个iframe时,如何从主页向iframe发送数据