Javascript 代码镜像和iFrame问题
我正在我的一个项目中使用Codemirror。 代码如下:Javascript 代码镜像和iFrame问题,javascript,jquery,html,css,iframe,Javascript,Jquery,Html,Css,Iframe,我正在我的一个项目中使用Codemirror。 代码如下: <script> window.onload = function() { var te = document.getElementById("js"); var te_html = document.getElementById("html"); var te_css = document.getElementById("css"); window.editor = CodeMirror.fromTextArea(te,
<script>
window.onload = function() {
var te = document.getElementById("js");
var te_html = document.getElementById("html");
var te_css = document.getElementById("css");
window.editor = CodeMirror.fromTextArea(te, {
mode: "javascript",
lineWrapping: true,
});
window.editor_css = CodeMirror.fromTextArea(te_css, {
mode: "css",
lineWrapping: true,
});
window.editor_html = CodeMirror.fromTextArea(te_html, {
mode: "text/html",
lineWrapping: true,
})
};
</script>
window.onload=函数(){
var te=document.getElementById(“js”);
var te_html=document.getElementById(“html”);
var te_css=document.getElementById(“css”);
window.editor=CodeMirror.fromTextArea(te{
模式:“javascript”,
换行:对,
});
window.editor\u css=code镜像.fromTextArea(te\u css{
模式:“css”,
换行:对,
});
window.editor_html=code镜像.fromTextArea(te_html{
模式:“文本/html”,
换行:对,
})
};
我还使用Jeffrey Way的“如何将自定义HTML和CSS注入iframe”脚本来构建类似Tinkerbin或JSFIDLE的东西
以下是我对该部分的代码:
<script type="text/javascript">
(function() {
$('.grid').height( $(window).height() );
var contents = $('iframe').contents(),
body = contents.find('body'),
styleTag = $('<style></style>').appendTo(contents.find('head'));
$('textarea').keyup(function() {
var $this = $(this);
if ( $this.attr('id') === 'html')
{
body.html( $this.val() );
}
else
{
styleTag.html( $this.val() );
}
});
})();
</script>
(功能(){
$('.grid').height($(window.height());
var contents=$('iframe').contents(),
body=contents.find('body'),
styleTag=$('').appendTo(contents.find('head');
$('textarea').keyup(函数(){
var$this=$(this);
if($this.attr('id')='html')
{
html($this.val());
}
其他的
{
html($this.val());
}
});
})();
这一切都很好,除了激活CodeMirror脚本后,结果选项卡中没有显示任何内容。如果我删除CodeMirror代码部分,它可以正常工作
以下是我的项目链接:
有人知道冲突在哪里吗
谢谢大家! 确保您已加载所有Java脚本
mode/javascript.js
mode/css.js
mode/xml.js
如果您在xhtml文件中使用此脚本。使用单引号(”
)代替双引号(“
)
前
window.onload=函数(){
var te=document.getElementById('js');
var te_html=document.getElementById('html');
var te_css=document.getElementById('css');
window.editor=CodeMirror.fromTextArea(te{
模式:“javascript”,
换行:对,
});
window.editor\u css=code镜像.fromTextArea(te\u css{
模式:“css”,
换行:对,
});
window.editor_html=code镜像.fromTextArea(te_html{
模式:“text/html”,
换行:对,
})
};
Jeffrey Way的如何将自定义HTML和CSS注入iframe…与加载codemirror脚本无关
<script>
window.onload = function() {
var te = document.getElementById('js');
var te_html = document.getElementById('html');
var te_css = document.getElementById('css');
window.editor = CodeMirror.fromTextArea(te, {
mode: 'javascript',
lineWrapping: true,
});
window.editor_css = CodeMirror.fromTextArea(te_css, {
mode: 'css',
lineWrapping: true,
});
window.editor_html = CodeMirror.fromTextArea(te_html, {
mode: 'text/html',
lineWrapping: true,
})
};
</script>