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 ">#codeinp {font-size:14px; font-family: ' Courier '; } . btnbar {margin-top:5px;} A {font-size:14px; text-decoration:none; margin:5px;}</style>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!" "); } }; } })();
Run the HTML code device online