Yesterday's "Use Th,colgroup,col definition table Style", careful friend will find added a "Run Code" link: Direct click can run textarea content. In fact, the blue ideal, the 51JS also has related introduction, Z-blog official forum also have similar posts, because they do not like to change the content of ASP (in the future upgrade saves the replacement), so stole a little lazy, made a pure JS version of.
is compatible with Firefox, has not yet time to test. I think "Save as" and "copy" function is also more superfluous, here also omitted. If you need fix bugs or technical support, please leave me a message ^_^ specific code as follows:
Copy Code code as follows:
function RunCode () {
var ele = document.getElementsByTagName ("textarea");
for (var i=0; i<ele.length; i++) {
With (Ele[i]) {
if (className!= "code") continue;
var o = document.createelement ("P");
var a = document.createelement ("a");
var em = document.createelement ("em");
O.classname = "RunCode";
A.href = "javascript:;";
a.innerhtml = "Run Code";
A.onclick = function () {
var win = window.open ("," "_blank", "");
Win.document.open (' text/html ', ' replace ');
Win.document.writeln (This.parentNode.previousSibling.value.replace (/\u00a0/gi, ""));
Win.document.close ();
}
em.innerhtml = "(Hint: You can modify some of the code before running)";
O.appendchild (a);
O.appendchild (EM);
Insertadjacentelement ("Afterend", O);
}
}
}
Currently the "Run code" function is placed below the textarea, if you want to put above, change the following code.
Insertadjacentelement ("Afterend", O);
This.parentNode.previousSibling.value
The Replace (/\u00a0/gi, "") is primarily intended to restore the space () and tab () that are replaced by the c_function.asp file. The use of course is in the desired page onload come in, how many classname for the code textarea, there are how many "run code" function, simple enough?