<html> <head><title>JS、HTML代码运行工具</title><SCRIPT LANGUAGE="JavaScript">function copyCode(obj) { if(obj.value==""){ alert("请输入要复制的代码内容");return false;}var rng = document.body.createTextRange();rng.moveToElementText(obj);rng.scrollIntoView();rng.select();rng.execCommand("Copy");rng.collapse(false);}function runCode(obj) { if(obj.value==""){ alert("请输入要运行的代码内容");return false;}var winname = window.open('', "_blank", '');winname.document.open('text/html', 'replace');winname.document.writeln(obj.value);winname.document.close();}function saveCode(obj) { if(obj.value==""){ alert("请输入要保存的代码内容");return false;}var winname = window.open('', '_blank', '');winname.document.open('text/html', 'replace');winname.document.writeln(obj.value);winname.document.close();winname.document.execCommand('saveas','','savecode.htm');winname.close();}</SCRIPT></head><body> <B>JS、HTML运行工具</B><textarea name="textarea" style="width:96%" rows="33" id="testcode"></textarea> <input name="button" type="button" οnclick="runCode(testcode)" value="运行代码"> <input name="button" type="button" οnclick="copyCode(testcode)" value="复制代码"> <input name="button" type="button" οnclick="saveCode(testcode)" value="保存代码"> <input name="button" type="button" οnclick="document.getElementById('testcode').value='';" value="清空代码"></body></html> |