JS基礎知識

來源:互聯網
上載者:User

標籤:

JavaScript事件列表

一般事件:主要是滑鼠擦偶偶

頁面事件:onload(頁面內容完成時觸發此事件)、onmove(瀏覽器視窗被移動)、onresize(瀏覽器視窗大小改變)、onstop(瀏覽器停止按鈕被按下或正在下載的檔案被中斷)、onabort(在下載時被使用者中斷)

表單事件:onsubmit(表單事件被觸發時提交)

 

JavaScript常用內部對象

Object 提供自訂對象,不需要定義建構函式

String 動態對象,只有建立執行個體後,才能引用其屬性和方法

           ----------------- length、indexOf、replace、substr(返回指定位置,指定長度)、substring(返回從一個開始位置到另一個結束位置間的所有字串)、toLowerCase、toUpperCase

Array 建立數組,可對其進行排序、刪除等操作

Document 該對象是與文件項目(element)一起工作的對象  

          ----------------write、writeln(與write相似,但輸出文本隨後空一格)、open(清除當前文檔,寫入指定類型資料流)、close(關閉文檔輸入資料流)

 

1、定時器相關知識

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>無標題文檔</title> </head><body onload="progress_update()"><div id="demo" style="border:solid #0000FF 2px"></div><script type="text/javascript"> var prosressInterval=60; var progressBegin=0; var  progressEnd=30; var progressTimer; function progress_clear() {     //清空定時器     clearTimeout(progressTimer);     //隱藏div     document.getElementById("demo").style.visibility="hidden"; } function progress_update() {     progressBegin++;     if(progressBegin>progressEnd)    //progress_clear();      clearTimeout(progressTimer);    else        // document.getElementById("demo").style.backgroundColor="blue";        document.write("<br>"+progressBegin+" ");    progressTimer=setTimeout("progress_update()",prosressInterval);  }</script></body></html>

2、函數相關知識

這個例子主要是舉了建立Student類的屬性、方法,以及其調用方法

var obj=new objName(參數);

for(var property in student){ alert(flag+property+" "+student[property]);}

可用以上的方法查看student中各個屬性和方法

<!DOCTYPE html><head></head><body onload="progress_update()"><div id="demo" style="border:solid #0000FF 2px"></div><div><input id="txt1" type="text"  /><input id="txt2" type="text"  /><input id="but1" type="button" onclick="Study()"  /></div><script type="text/javascript">//自訂函數//function 函數名(參數)//{code;return expression;}//對象的建立function Student(name,age){this.name=name;this.age=age;this.Read=Read;//注意調用方法Read()這個用法}function Read(){alert(this.name+"正在讀書");}function Study(){var student=new Student(txt1.value,txt2.value);student.Read();} </script></body></html>

 注意:

1、要著重掌握好string的基本用法

2、計時器很可能會用到

3、document.write("content"),document.getElementById("id")

4、js中區分字母大小寫,注釋、基本文法與C系語言相同

JS中innerHTML,innerText,value  的區別

 

JS基礎知識

聯繫我們

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