In yesterday's "Using th, colgroup, col to define table styles", careful friends will find that a "run code" link is added: click directly to run the content in the Textarea. In fact, there are related introductions on Blue Ideal and 51JS, and there are similar posts on the Z-Blog official forum. Because I don’t like changing the content of asp (I won’t have to replace it when I upgrade in the future), so I was lazy and made a pure JS version.
I haven’t had time to test whether it is compatible with FireFox. I feel that the "Save As" and "Copy" functions are also redundant, so I have omitted them here. If you need Fix Bug or technical support, please leave me a message ^_^ The specific code is as follows:
function RunCode() {
var ele = document.getElementsByTagName("textarea");
for (var i=0; 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 = "(Tip: You can modify part of the code before running)";
o.appendChild(a);
o.appendChild(em);
insertAdjacentElement("afterEnd",o ;
insertAdjacentElement("afterEnd",o);
this.parentNode.previousSibling.value
The replace(/u00a0/gi, " ") is mainly for the spaces replaced by the c_function.asp file ( ) and Tab( ) to restore it. In terms of usage, of course, just onload the required page. There are as many "run code" functions as there are Textareas whose className is code. Is it simple enough?