一個可以編寫簡單的JavaScript的頁面

來源:互聯網
上載者:User

在這個頁面中可以簡單的測試一些簡單的JavaScript語句

JavaScript代碼

 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

以上是從一個實驗的例子中找出的,貼出來和大家分享,也是自己儲存,呵呵……

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.