设为首页 加入收藏

TOP

【前端】向blog或网站中添加语法高亮显示代码方法总结(二)
2017-10-10 15:22:35 】 浏览:8326
Tags:前端 blog 网站 添加 语法 高亮 显示 代码 方法 总结
; </head> <body> <h1>Highlight.js</h1> <pre> <code class="java script"> function selectionSort(arr){ var minIndex, temp, len = arr.length; for(var i=0; i < len; i++){ minIndex = i; for(var j=i+1; j < len; j++){ if(arr[j] < arr[minIndex]){ minIndex = j; } } temp = arr[i]; arr[i] = arr[minIndex]; arr[minIndex] = temp; } return arr; } var num = new Array; num = [1,5,2,8,4,9,3,0,4]; console.log(selectionSort(num)); </code> </pre> </body> </html>

 

实现效果:

 

 

Prism.js

使用方法:

<!DOCTYPE html>
<html>
<head>
	<title>prism.js</title>
	<meta charset="utf-8">
	
	<link rel="stylesheet" type="text/css" href="./assets/css/algorithm.css">
	<link rel="stylesheet" type="text/css" href="./prism/prism.css">
	<script src="./prism/prism.js"></script>
</head>
<body>
<h1>prism.js</h1>
<pre>
	<code class="language-java script">
		function selectionSort(arr){
			var minIndex, temp, len = arr.length;
			for(var i=0; i < len; i++){
				minIndex = i;
				for(var j=i+1; j < len; j++){
					if(arr[j] < arr[minIndex]){
						minIndex = j;
					}
				}
				temp = arr[i];
				arr[i] = arr[minIndex];
				arr[minIndex] = temp;
			}
			return arr;
		}
		var num = new Array;
		num = [1,5,2,8,4,9,3,0,4];
		console.log(selectionSort(num));
	</code>
</pre>


</body>
</html>

  

实现效果:

 

 

Google Prettify 

使用方法:

<!DOCTYPE html>
<html>
<head>
	<title>prettify.js</title>
	<meta charset="utf-8">

	<!-- 
	Include the script tag below in your document:
	<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
	See Getting Started to configure that URL with options you need.
	Look at the skin gallery and pick styles that suit you. 
	-->

	<!-- 
	Put code snippets in <pre class="prettyprint">...</pre> or <code class="prettyprint">...</code> and it will automatically be pretty-printed. 
	-->
	
	<link rel="stylesheet" type="text/css" href="./assets/css/algorithm.css">
	<script src="./prettify/loader/run_prettify.js"></script>
</head>
<body>
<h1>prettify.js</h1>
<pre>
	<code class="prettyprint">
		function selectionSort(arr){
			var minIndex, temp, len = arr.length;
			for(var i=0; i < len; i++){
				minIndex = i;
				for(var j=i+1; j < len; j++){
					if(arr[j] < arr[minIndex]){
						minIndex = j;
					}
				}
				temp = arr[i];
				arr[i] = arr[minIndex];
				arr[minIndex] = temp;
			}
			return arr;
		}
		var num = new Array;
		num = [1,5,2,8,4,9,3,0,4];
		console.log(selectionSort(num));
	</code>
</pre>
</body>
</html>

 

实现效果:

 

 


 

第三类方法:忽略HTMLPHP

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇checkbox框变大变小 下一篇CORS跨域资源共享你该知道的事儿

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目