Run the HTML code on line (two) and the previous (a) the same, the key part of the JS code, this time is the operation of all the JS function to focus together. The following is the HTML code:
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/><title>Run the HTML code device online (ii)</title><Scripttype= "Text/javascript"src= "Runcode.js"></Script><style>#codeinp{font-size:14px;font-family:' Courier '; }. Btnbar{Margin-top:5px; }a{font-size:14px;text-decoration:None;margin:5px; }</style></Head><BodyID= "Nv_tools"class= "Pg_runcode Widthauto"onkeydown= "if (event.keycode==27) return false;"> <Divclass= "Content"> <DivID= "Code"class= "TextBox"> <Div><textareaID= "CODEINP"rows= "8"cols= "Max">Stick the HTML code here and click Run.</textarea></Div> </Div> <Divclass= "Btnbar"> <aID= "Btclear"class= "Btns"href= "javascript:void (0);"Hidefocus= "true">Empty</a> <aID= "Btrun"class= "Btns hilite"href= "javascript:void (0);"Hidefocus= "true">Run</a> </Div> </Div></Body></HTML>
The following is the JS code:
( function() {window.onload=function() { varTips = "Stick the HTML code here and click to run." "; varCODEINP = document.getElementById ("Codeinp"); varBtclear = document.getElementById ("Btclear"); varBtrun = document.getElementById ("Btrun"); //tips disappear after clicking the boxCodeinp.onfocus =function() { varCode =Codeinp.value; Code= = Tips && (codeinp.value = "");//when the value in textarea is tips, it is emptied. Description: If the value of the && left expression is true, the value of the right expression is returned. }; //Recovery TipsCodeinp.onblur =function()// { varCode =Codeinp.value; Code= = "" && (Codeinp.value = tips);//when the value in textarea is cleared, it is rewritten as a tips }; //click "Empty" to empty textareaBtclear.onclick =function() {Codeinp.value= "";//The value in the TextArea box is emptied when you click "Empty"Codeinp.focus ();//cursor focus TEXTAREA box }; //Click "Run" to runBtrun.onclick =function() { varCode =Codeinp.value; if(Code! = Tips)//if the value in textarea is not a tips, run the code, or the popup alert { varNewwin = window.open (', ', ', '); Newwin.opener=NULL; Newwin.document.write (code); Newwin.document.close (); } Else{alert ("Please fill in the required HTML into the input box and then run!" "); } }; } })();
The effect is as follows:
Run the HTML code device online (ii)