When I work and study, I often encounter the need to view the execution results of the JavaScript code compiled by myself. It's okay in Firefox, but there is firebug, but IE6 won't work well, so, it makes a simple page to view the execution result of JavaScript code. js code can contain single lines (// comment content) and multiple lines of comments (/* Comment content */) (The content is super Elementary, free to play, please fly ).
The complete HTML page code is as follows:
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> JavaScript test tool! </Title>
<Meta name = "author" content = "yakoo5@163.com">
<Meta name = "Description" content = "a webpage that can directly execute JavaScript">
</Head>
<Body>
<Br/>
<Br/>
<H2>
<Font color = "blue"> A webpage that can directly execute JavaScript! </Font>
</H2>
Author: <a href = "mailto: yakoo5@163.com"> yakoo5@163.com </a> <br/>
Date: 2010-11-26 <br/>
Version: 1.1
<HR/>
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
Function executejs (){
VaR Codes = Document. getelementbyid ('Codes '). value;
If (''= codes ){
Alert ('Enter the code! ');
Return;
}
VaR codearray = codes. Split ('\ n ');
VaR purecode = ''; // stores pure JavaScript code that removes" // "single-line comments
For (VAR I = 0; I <codearray. length; I ++ ){
VaR code = codearray [I];
If (code. indexof ('//')>-1 ){
Code = code. substr (0, code. indexof ('//'));
} Else if (''! = Code &&! /^ \ S * $/. Test (CODE )){
Code = trim (CODE );
}
Purecode + = code + '\ n ';
}
Try {
Eval (purecode );
} Catch (exception ){
Alert (exception );
}
}
// Remove spaces at both ends of the string
Function trim (STR ){
If (null! = Str) return Str. Replace (/^ \ s +/, ''). Replace (/(\ s +) $ /,'');
Else return STR;
}
</SCRIPT>
<Br/>
Enter the JavaScript code in the text box below and click & nbsp;
<Input type = "button" value = "running" onclick = "executejs ()">
& Nbsp; view the result.
<Br/>
<Textarea id = "codes" rows = "15" Cols = "100"> alert ('Hello! '); </Textarea>
</Body>
</Html>
You can copy the above Code and save it as an HTML page to view the effect.