Javascript: Javascript special effect: convert HTML into Javascript code automatically.
Sometimes you need to use Javascript to enter common characters, such as a footer for every page. Here is a conversion script:
SCRIPT function Preview (obj) {var TestWin = open (''); TestWin.doc ument. write (obj. value);} function copyCode (obj) {var rng = document. body. createTextRange (); rng. moveToElementText (obj); rng. scrollIntoView (); rng. select (); rng.exe cCommand ("Copy"); rng. collapse (false);} function saveCode (obj) {var winname = window. open ('', '_ blank', 'top = 10000 '); winname.doc ument. open ('text/html ', 'replace'); winname.doc ument. writeln (obj. value); winname.document.execcommand('saveas', '', 'homepage.yesky.com.htm '); winname. close ();} SCRIPTScript function toScript (val) {var value = val. value = value. replace (// gi ,"\\\\"). replace (/"/gi ,"\\\""). replace (/'/gi, "\\\'") valArr = value. split ("\ r \ n") value = "" for (I = 0; I <valArr. length; I ++) {value + = (I = 0 )? "Info =": "" value + = "\" "+ valArr [I] value + = (I! = ValArr. length-1 )? "\" + \ "\ N \" + \ n ":" \ "\ n"} value + = "\ ndocument. write (info) "val. value = value} script <input type = button value = "convert HTML to JavaScript" onclick = toScript (document. all ["code"])> <br> <textarea id = code cols = 75 rows = 20> <table width = "200" border = "1"> <tr> <td> </td> <td> </td> </tr> <td> </td> </tr> </table>
Run codeCopy codeSave code