|
示例
1
:
不使用css
示例
2
:
使用css
示例
3
:
不同的td有不同的背景色
不使用css 给每一个单元格加上背景颜色
就需要给每一个td元素加上bgcolor属性
");
window.frames["iframe_show446"].document.write(decodeHtml($("textarea#stepcodeTextarea446").val()));
window.frames["iframe_show446"].document.close();
$(window.frames["iframe_show446"]).load(function(){
$("#iframe_show446").height($("#iframe_show446").contents().find("body").height()+showittryitheight);
});
$("#iframe_show446").height($("#iframe_show446").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<table border="1">
<tr >
<td bgcolor="gray" >1</td>
<td bgcolor="gray">2</td>
</tr>
<tr>
<td bgcolor="gray">3</td>
<td bgcolor="gray">4</td>
</tr>
<tr>
<td bgcolor="gray">a</td>
<td bgcolor="gray">b</td>
</tr>
</table>
<table border="1">
<tr >
<td bgcolor="gray" >1</td>
<td bgcolor="gray">2</td>
</tr>
<tr>
<td bgcolor="gray">3</td>
<td bgcolor="gray">4</td>
</tr>
<tr>
<td bgcolor="gray">a</td>
<td bgcolor="gray">b</td>
</tr>
</table>
");
window.frames["iframe446"].document.write(decodeHtml(code446));
window.frames["iframe446"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe446"]).load(function(){
$("#iframe446").height($("#iframe446").contents().find("body").height()+showittryitheight);
});
$("#iframe446").height($("#iframe446").contents().find("body").height()+showittryitheight);
alreadyWriteCode446 = code446;
$("#rendering446").hide();
$("#rendered446").show();
}
var tRereshRetry2DemoPanel446 = setInterval(rereshRetry2DemoPanel446,1000);
var binded446 = false;
$("textarea#stepcodeTextarea446").keyup(function(){
if(!binded446){
$(window).bind('beforeunload',function(){
binded446 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code446 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code446!=newCode){
// window.frames["iframe446"].document.write("
");
// window.frames["iframe446"].document.write(decodeHtml($("textarea#stepcodeTextarea446").val()));
// window.frames["iframe446"].document.close();
// $(window.frames["iframe446"]).load(function(){
// $("#iframe446").height($("#iframe446").contents().find("body").height()+showittryitheight);
// });
// code446 = newCode;
// }
});
$(".tryButton446").click(function(){
$("#tryDiv446").show();
$("#stepcodeTextarea446").focus();
$("#stepcodeTextarea446").height(200);
$("#iframe446").height(0);
window.frames["iframe446"].document.write("
");
window.frames["iframe446"].document.write(decodeHtml($("textarea#stepcodeTextarea446").val()));
window.frames["iframe446"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe446"]).load(function(){
$("#iframe446").height($("#iframe446").contents().find("body").height()+showittryitheight);
});
$("#iframe446").height($("#iframe446").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor446.focus();
editor446.setSize(null, "250");
$("#rendering446").hide();
$("#rendered446").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 editor446 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea446"), {
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);
}
}
});
editor446.on("change",function(doc){
if(!binded446){
$(window).bind('beforeunload',function(){
binded446 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code446 = newCode;
$("textarea#stepcodeTextarea446").val(newCode);
if(alreadyWriteCode446!=code446){
lastModifedTime446 = new Date().getTime();
$("#rendering446").show();
$("#rendered446").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor446 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor446.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv446").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
使用css 给每一个单元格加上背景颜色 只需要在最前面写一段css代码,所有的单元格都有背景颜色了
这是一种分层设计的思想,css把和颜色,大小位置等信息剥离到<style>中,而html只用关心提供什么样的内容就行了。
");
window.frames["iframe_show447"].document.write(decodeHtml($("textarea#stepcodeTextarea447").val()));
window.frames["iframe_show447"].document.close();
$(window.frames["iframe_show447"]).load(function(){
$("#iframe_show447").height($("#iframe_show447").contents().find("body").height()+showittryitheight);
});
$("#iframe_show447").height($("#iframe_show447").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<style>
td{
background-color:gray;
}
</style>
<table border="1">
<tr >
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>a</td>
<td>b</td>
</tr>
</table>
<style>
td{
background-color:gray;
}
</style>
<table border="1">
<tr >
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>a</td>
<td>b</td>
</tr>
</table>
");
window.frames["iframe447"].document.write(decodeHtml(code447));
window.frames["iframe447"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe447"]).load(function(){
$("#iframe447").height($("#iframe447").contents().find("body").height()+showittryitheight);
});
$("#iframe447").height($("#iframe447").contents().find("body").height()+showittryitheight);
alreadyWriteCode447 = code447;
$("#rendering447").hide();
$("#rendered447").show();
}
var tRereshRetry2DemoPanel447 = setInterval(rereshRetry2DemoPanel447,1000);
var binded447 = false;
$("textarea#stepcodeTextarea447").keyup(function(){
if(!binded447){
$(window).bind('beforeunload',function(){
binded447 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code447 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code447!=newCode){
// window.frames["iframe447"].document.write("
");
// window.frames["iframe447"].document.write(decodeHtml($("textarea#stepcodeTextarea447").val()));
// window.frames["iframe447"].document.close();
// $(window.frames["iframe447"]).load(function(){
// $("#iframe447").height($("#iframe447").contents().find("body").height()+showittryitheight);
// });
// code447 = newCode;
// }
});
$(".tryButton447").click(function(){
$("#tryDiv447").show();
$("#stepcodeTextarea447").focus();
$("#stepcodeTextarea447").height(200);
$("#iframe447").height(0);
window.frames["iframe447"].document.write("
");
window.frames["iframe447"].document.write(decodeHtml($("textarea#stepcodeTextarea447").val()));
window.frames["iframe447"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe447"]).load(function(){
$("#iframe447").height($("#iframe447").contents().find("body").height()+showittryitheight);
});
$("#iframe447").height($("#iframe447").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor447.focus();
editor447.setSize(null, "250");
$("#rendering447").hide();
$("#rendered447").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 editor447 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea447"), {
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);
}
}
});
editor447.on("change",function(doc){
if(!binded447){
$(window).bind('beforeunload',function(){
binded447 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code447 = newCode;
$("textarea#stepcodeTextarea447").val(newCode);
if(alreadyWriteCode447!=code447){
lastModifedTime447 = new Date().getTime();
$("#rendering447").show();
$("#rendered447").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor447 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor447.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv447").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|