how2j.cn


工具版本兼容问题
使用css和不使用比较

示例 1 : 不使用css   
示例 2 : 使用css   
示例 3 : 不同的td有不同的背景色   

示例 1 :

不使用css

不使用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 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 2 :

使用css

使用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>
"); 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 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 3 :

不同的td有不同的背景色

这就涉及到选择器的知识,请看选择器章节


HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。


关于 前端部分-CSS-CSS教程 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 620943819
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: http://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图