Yesterday's "using th, colgroup, col to define Table Styles", a careful friend will find that a "run code" link is added: directly click to run the content in Textarea. In fact, there are also related introductions on Blue ideal and 51JS, and there are similar posts on the official Z-Blog Forum, because I do not like to change asp content (upgrade in the future to save replacement ), so I stole a little lazy and made a pure JS version.
It is not time to test whether it is compatible with FireFox. I think the functions of "Save as" and "copy" are redundant, which is also omitted here. If you need to Fix a Bug or technical support, please leave a message. The Code is as follows:
Copy codeThe Code is 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 ("");
Var em = document. createElement ("em ");
O. className = "runCode ";
A. href = "javascript :;";
A. innerHTML = "Running code ";
A. onclick = function (){
Var win = window. open (''," _ blank ",'');
Win.doc ument. open ('text/html ', 'replace ');
Win.doc ument. writeln (this. parentNode. previussibling. value. replace (/\ u00a0/gi ,""));
Win.doc ument. close ();
}
Em. innerHTML = "(Prompt: you can modify some code before running )";
O. appendChild ();
O. appendChild (em );
InsertAdjacentElement ("afterEnd", o );
}
}
}
Currently, the "run code" function is placed below Textarea. If you want to put it above, modify the following code.
InsertAdjacentElement ("afterEnd", o );
This. parentNode. previussibling. value
Replace (/\ u00a0/gi, "") is used to restore the spaces () and Tab () replaced by the c_function.asp file. In terms of usage, of course, you just need to load the required page in onload. How many "run code" functions are available for Textarea whose className is code?