JavaScript學習筆記1

來源:互聯網
上載者:User

標籤:

 1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4     <meta charset="UTF-8"> 5     <title></title> 6 </head> 7 <body> 8 <!-- 9 JavaScript用法:10 html中的指令碼必須位於<script></script>標籤中11 指令碼可被放置在html頁面的<body>和<head>中12 使用限制:13 在html中,不限制指令碼數量14 通常會把指令碼放置於<head>標籤中,以不干擾頁面內容15 -->16 <input type="text" id="txt"/>17 <input type="button" id="btn" onclick="errDemo2()" value="提交"/>18 <!-- onclick:單擊事件19      onChange:常值內容改變事件20      onUnload:關閉網頁事件21      onMouseOver:滑鼠經過事件22      OnMouseOut:滑鼠移出事件23      等等...24    -->25 <script>26     document.write("Hello JavaScript");//代碼按照編寫順序依次執行27     document.write("Hello JS");28     var i= 10;//用var聲明變數,全域變數29     //函數:當它被調用時執行的可重複使用的代碼塊30     //帶參數的函數31     function demo(a,b){32         var a = 10;//局部變數33         b = 20;//全域變數34         document.write(a+b);35     }36     demo();//調用函數37 38     //帶傳回值的函數39     function demo2(){40         return "Hello";41     }42     var m = demo2();43     document.write(m);44 45     //異常處理46     function errDemo(){47         try{48             document.write(str);//發生異常的代碼塊49         }catch (err){50             document.write(err);//錯誤資訊處理51         }52     }53 //    errDemo();54     function errDemo2(){55         try{56             var h = document.getElementById("txt").value;57             if(h==""){58                 throw "未定義";//通過throw語句建立一個自訂錯誤59             }60         }catch (err){61             alert(err);62         }63     }64 </script>65 </body>66 </html>

一些基礎的東西

JavaScript學習筆記1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.