平时在很多论坛或者博客中,都可以看到作者或者评论者的文章中,都会摆出一段代码,并且能实现在线测试.
实现此功能的代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content="MapleJan" />
<title>Run Code</title>
<meta name="description" content="在网页上测试文本框中的代码.">
<script>
function runCode(textId) {
var code = document.getElementById(textId).value;
var newWindow = window.open();
newWindow.opener = null; //对创建该窗口(newWindow)的Window不进行任何操作.
newWindow.document.write(code);
newWindow.document.close(); //关闭open()方法打开的文文档流.
};
function copyCode(textId) {
if(window.clipboardData) { //判断浏览器,目前仅支持IE
var