在線運行Javascript,Jquery,HTML,CSS代碼

<!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>
<title>在線運行Javascript,Jquery,HTML,CSS代碼</title>
<script type="text/javascript">
var userAgent = navigator.userAgent.toLowerCase();
var is_webtv = userAgent.indexOf('webtv') != -1;
var is_kon = userAgent.indexOf('konqueror') != -1;
var is_mac = userAgent.indexOf('mac') != -1;
var is_saf = userAgent.indexOf('applewebkit') != -1 || navigator.vendor == 'Apple Computer, Inc.';
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko' && !is_saf) && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ns = userAgent.indexOf('compatible') == -1 && userAgent.indexOf('mozilla') != -1 && !is_opera && !is_webtv && !is_saf;
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera && !is_saf && !is_webtv) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

function $(id) {
return document.getElementById(id);
}

function copyCode(obj) {
if(is_ie && obj.style.display != 'none') {
   var rng = document.body.createTextRange();
   rng.moveToElementText(obj);
   rng.scrollIntoView();
   rng.select();
   rng.execCommand("Copy");
   rng.collapse(false);
}
}

function runCode(obj) {
var winname = window.open('', "_blank", '');
winname.document.open('text/html', 'replace');
winname.document.write(obj.value);
winname.document.close();
}

function saveCode(obj) {
var winname = window.open('', '_blank', 'top=10000');
winname.document.open('text/html', 'replace');
winname.document.writeln(obj.value);
winname.document.execCommand('saveas','','code.htm');
winname.close();
}
</script>
</head>

<body onkeydown="if(event.keyCode==27) return false;">
<span>請在下面輸入 HTML 代碼段</span><p>
<textarea id="code0" rows="30" cols="160">
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>在線運行</title>
<style>

</style>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<head>
<body>
  <div>這兒爲頁面內容</div>
<script type="text/javascript">
$(document).ready(function(e) {
	//這兒加載頁面加載完成後執行的代碼
});
</script>
</body>
</html>
</textarea><p>
<input type="button" value="運行代碼" onclick="runCode($('code0'))"> 
<input type="button" value="複製代碼" onclick="copyCode($('code0'))"> 
<input type="button" value="另存代碼" onclick="saveCode($('code0'))"> 
提示:您能夠修改上面部分代碼後再從新運行
</body></html>
相關文章
相關標籤/搜索