在这个页面中可以简单的测试一些简单的JavaScript语句
![ContractedBlock.gif](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
2 < html xmlns ="http://www.w3.org/1999/xhtml" >
3 < head >
4 < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
5 < title > 可以再代码框中编写简单的JavaScript </ title >
6 < script language ="javascript" type ="text/javascript" >
7 function btn_onclick()
8 {
9 try
10 {
11 var cmdWin = document.getElementById( " txtre " ); // 获取文本id
12 var str = " try{ " + cmdWin.value + " } catch(e){alert('你的代码有错:'+e.description);} " ; // 构造函数体,这里的e.description用来输出你输入的JavaScript代码的错误信息
13 var cmd = new Function(str); // 构造函数
14 cmd(); // 调用函数
15 }
16 catch (e)
17 {
18 alert( " 错误: " + e.description); // 输出错误信息,这里用来处理本段JavaScript代码的错误信息
19 }
20 }
21 </ script >
22 </ head >
23
24 < body >
25 <!-- 用户界面,一文本框,一按钮 -->
26
27 < div align ="center" style ="boeder-right:#000000 1px solid; boeder-top:#000 1px solid; border-left:#000 1px solid; width:618px;border-right:#000 1px solid;height:336px;background-color:#FF0" >
28 < textarea id ="txtre" style ="width:612px;height;300px" >
29 </ textarea >
30 < input id ="btnTest" type ="button" value ="执行程序" onclick ="return btn_onclick()" style ="width:145ppx" />
31 </ div >
32 </ body >
33 </ html >
34
2 < html xmlns ="http://www.w3.org/1999/xhtml" >
3 < head >
4 < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
5 < title > 可以再代码框中编写简单的JavaScript </ title >
6 < script language ="javascript" type ="text/javascript" >
7 function btn_onclick()
8 {
9 try
10 {
11 var cmdWin = document.getElementById( " txtre " ); // 获取文本id
12 var str = " try{ " + cmdWin.value + " } catch(e){alert('你的代码有错:'+e.description);} " ; // 构造函数体,这里的e.description用来输出你输入的JavaScript代码的错误信息
13 var cmd = new Function(str); // 构造函数
14 cmd(); // 调用函数
15 }
16 catch (e)
17 {
18 alert( " 错误: " + e.description); // 输出错误信息,这里用来处理本段JavaScript代码的错误信息
19 }
20 }
21 </ script >
22 </ head >
23
24 < body >
25 <!-- 用户界面,一文本框,一按钮 -->
26
27 < div align ="center" style ="boeder-right:#000000 1px solid; boeder-top:#000 1px solid; border-left:#000 1px solid; width:618px;border-right:#000 1px solid;height:336px;background-color:#FF0" >
28 < textarea id ="txtre" style ="width:612px;height;300px" >
29 </ textarea >
30 < input id ="btnTest" type ="button" value ="执行程序" onclick ="return btn_onclick()" style ="width:145ppx" />
31 </ div >
32 </ body >
33 </ html >
34
以上是从一个实验的例子中找出的,贴出来和大家分享,也是自己保存,呵呵……