|
工具版本兼容问题
元素指的是从开始标签到结束标签之间所有的代码
比如
<p>HelloWord</p>
示例
1
:
完整的HTML
示例
2
:
不完整的元素
示例
3
:
有的特殊元素
一个完整的HTML文件,应该至少包含html元素,body元素,以及里面的内容
");
window.frames["iframe_show318"].document.write(decodeHtml($("textarea#stepcodeTextarea318").val()));
window.frames["iframe_show318"].document.close();
$(window.frames["iframe_show318"]).load(function(){
$("#iframe_show318").height($("#iframe_show318").contents().find("body").height()+showittryitheight);
});
$("#iframe_show318").height($("#iframe_show318").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<html>
<body>
<h1>标题</h1>
</body>
</html>
<html>
<body>
<h1>标题</h1>
</body>
</html>
");
window.frames["iframe318"].document.write(decodeHtml(code318));
window.frames["iframe318"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe318"]).load(function(){
$("#iframe318").height($("#iframe318").contents().find("body").height()+showittryitheight);
});
$("#iframe318").height($("#iframe318").contents().find("body").height()+showittryitheight);
alreadyWriteCode318 = code318;
$("#rendering318").hide();
$("#rendered318").show();
}
var tRereshRetry2DemoPanel318 = setInterval(rereshRetry2DemoPanel318,1000);
var binded318 = false;
$("textarea#stepcodeTextarea318").keyup(function(){
if(!binded318){
$(window).bind('beforeunload',function(){
binded318 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code318 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code318!=newCode){
// window.frames["iframe318"].document.write("
");
// window.frames["iframe318"].document.write(decodeHtml($("textarea#stepcodeTextarea318").val()));
// window.frames["iframe318"].document.close();
// $(window.frames["iframe318"]).load(function(){
// $("#iframe318").height($("#iframe318").contents().find("body").height()+showittryitheight);
// });
// code318 = newCode;
// }
});
$(".tryButton318").click(function(){
$("#tryDiv318").show();
$("#stepcodeTextarea318").focus();
$("#stepcodeTextarea318").height(200);
$("#iframe318").height(0);
window.frames["iframe318"].document.write("
");
window.frames["iframe318"].document.write(decodeHtml($("textarea#stepcodeTextarea318").val()));
window.frames["iframe318"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe318"]).load(function(){
$("#iframe318").height($("#iframe318").contents().find("body").height()+showittryitheight);
});
$("#iframe318").height($("#iframe318").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor318.focus();
editor318.setSize(null, "250");
$("#rendering318").hide();
$("#rendered318").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor318 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea318"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor318.on("change",function(doc){
if(!binded318){
$(window).bind('beforeunload',function(){
binded318 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code318 = newCode;
$("textarea#stepcodeTextarea318").val(newCode);
if(alreadyWriteCode318!=code318){
lastModifedTime318 = new Date().getTime();
$("#rendering318").show();
$("#rendered318").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor318 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor318.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv318").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
实际开发中,我们即使一个元素不完整,也是可以正常显示的 但这不是因为你写的牛B,是因为浏览器很强大,浏览器能够渲染你写的“错误的代码” 不过,未来不一定能正常显示。 所以尽量把元素写的完整,即有开始标签也有结束标签
");
window.frames["iframe_show319"].document.write(decodeHtml($("textarea#stepcodeTextarea319").val()));
window.frames["iframe_show319"].document.close();
$(window.frames["iframe_show319"]).load(function(){
$("#iframe_show319").height($("#iframe_show319").contents().find("body").height()+showittryitheight);
});
$("#iframe_show319").height($("#iframe_show319").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
");
window.frames["iframe319"].document.write(decodeHtml(code319));
window.frames["iframe319"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe319"]).load(function(){
$("#iframe319").height($("#iframe319").contents().find("body").height()+showittryitheight);
});
$("#iframe319").height($("#iframe319").contents().find("body").height()+showittryitheight);
alreadyWriteCode319 = code319;
$("#rendering319").hide();
$("#rendered319").show();
}
var tRereshRetry2DemoPanel319 = setInterval(rereshRetry2DemoPanel319,1000);
var binded319 = false;
$("textarea#stepcodeTextarea319").keyup(function(){
if(!binded319){
$(window).bind('beforeunload',function(){
binded319 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code319 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code319!=newCode){
// window.frames["iframe319"].document.write("
");
// window.frames["iframe319"].document.write(decodeHtml($("textarea#stepcodeTextarea319").val()));
// window.frames["iframe319"].document.close();
// $(window.frames["iframe319"]).load(function(){
// $("#iframe319").height($("#iframe319").contents().find("body").height()+showittryitheight);
// });
// code319 = newCode;
// }
});
$(".tryButton319").click(function(){
$("#tryDiv319").show();
$("#stepcodeTextarea319").focus();
$("#stepcodeTextarea319").height(200);
$("#iframe319").height(0);
window.frames["iframe319"].document.write("
");
window.frames["iframe319"].document.write(decodeHtml($("textarea#stepcodeTextarea319").val()));
window.frames["iframe319"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe319"]).load(function(){
$("#iframe319").height($("#iframe319").contents().find("body").height()+showittryitheight);
});
$("#iframe319").height($("#iframe319").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor319.focus();
editor319.setSize(null, "250");
$("#rendering319").hide();
$("#rendered319").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor319 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea319"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor319.on("change",function(doc){
if(!binded319){
$(window).bind('beforeunload',function(){
binded319 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code319 = newCode;
$("textarea#stepcodeTextarea319").val(newCode);
if(alreadyWriteCode319!=code319){
lastModifedTime319 = new Date().getTime();
$("#rendering319").show();
$("#rendered319").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor319 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor319.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv319").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
有的特殊元素,没有内容,即开始和结束标签直接放在一起
比如BR HR
");
window.frames["iframe_show320"].document.write(decodeHtml($("textarea#stepcodeTextarea320").val()));
window.frames["iframe_show320"].document.close();
$(window.frames["iframe_show320"]).load(function(){
$("#iframe_show320").height($("#iframe_show320").contents().find("body").height()+showittryitheight);
});
$("#iframe_show320").height($("#iframe_show320").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<h1>标题1</h1>
<br/>
<br/>
<br/>
<h1>标题2前面有3个换行</h1>
<p>这是一个水平线,有渲染效果,但是没有文本内容</p>
<hr/>
<h1>标题1</h1>
<br/>
<br/>
<br/>
<h1>标题2前面有3个换行</h1>
<p>这是一个水平线,有渲染效果,但是没有文本内容</p>
<hr/>
");
window.frames["iframe320"].document.write(decodeHtml(code320));
window.frames["iframe320"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe320"]).load(function(){
$("#iframe320").height($("#iframe320").contents().find("body").height()+showittryitheight);
});
$("#iframe320").height($("#iframe320").contents().find("body").height()+showittryitheight);
alreadyWriteCode320 = code320;
$("#rendering320").hide();
$("#rendered320").show();
}
var tRereshRetry2DemoPanel320 = setInterval(rereshRetry2DemoPanel320,1000);
var binded320 = false;
$("textarea#stepcodeTextarea320").keyup(function(){
if(!binded320){
$(window).bind('beforeunload',function(){
binded320 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code320 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code320!=newCode){
// window.frames["iframe320"].document.write("
");
// window.frames["iframe320"].document.write(decodeHtml($("textarea#stepcodeTextarea320").val()));
// window.frames["iframe320"].document.close();
// $(window.frames["iframe320"]).load(function(){
// $("#iframe320").height($("#iframe320").contents().find("body").height()+showittryitheight);
// });
// code320 = newCode;
// }
});
$(".tryButton320").click(function(){
$("#tryDiv320").show();
$("#stepcodeTextarea320").focus();
$("#stepcodeTextarea320").height(200);
$("#iframe320").height(0);
window.frames["iframe320"].document.write("
");
window.frames["iframe320"].document.write(decodeHtml($("textarea#stepcodeTextarea320").val()));
window.frames["iframe320"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe320"]).load(function(){
$("#iframe320").height($("#iframe320").contents().find("body").height()+showittryitheight);
});
$("#iframe320").height($("#iframe320").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor320.focus();
editor320.setSize(null, "250");
$("#rendering320").hide();
$("#rendered320").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor320 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea320"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor320.on("change",function(doc){
if(!binded320){
$(window).bind('beforeunload',function(){
binded320 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code320 = newCode;
$("textarea#stepcodeTextarea320").val(newCode);
if(alreadyWriteCode320!=code320){
lastModifedTime320 = new Date().getTime();
$("#rendering320").show();
$("#rendered320").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor320 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor320.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv320").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|