如何创建 - 创建语法高亮
了解如何创建和使用语法高亮。
语法高亮
添加一些颜色后,代码片段更易于阅读:
<!DOCTYPE html>
<html>
<body>
<h1>Testing an HTML Syntax Highlighter</h2>
<p>Hello world!</p>
<a href="https://www.w3ccoo.com">Back to School</a>
</body>
</html>
<html>
<body>
<h1>Testing an HTML Syntax Highlighter</h2>
<p>Hello world!</p>
<a href="https://www.w3ccoo.com">Back to School</a>
</body>
</html>
如何创建语法高亮
步骤 1) 添加 HTML:
实例
A <div> containing HTML code:
<div id="myDiv">
<!DOCTYPE html><br>
<html><br>
<body><br>
<br>
<h1>Testing an HTML Syntax Highlighter</h2><br>
<p>Hello
world!</p><br>
<a href="https://www.w3ccoo.com">Back to
School</a><br>
<br>
</body><br>
</html>
</div>
第 2 步)添加 JavaScript:
实例
Create a function called "w3CodeColor" and call it, using the DIV element as a parameter:
w3CodeColor(document.getElementById("myDiv"));
function w3CodeColor(elmnt) {
// click "Try it Yourself" to see the JavaScript...
}
亲自试一试 »