1 / 8

認識物件

認識物件. Javascript 內建物件分為三大類 字串物件 數學物件 日期物件. 字串物件. 通常製造一個字串物件,最簡單的方法是指定一個文字常數給一個變數。 例: test= “ this is a test ” 常見的屬性或方法 length bold fontsize toLowerCase toUpperCase 使用方法 : 物件名 . 方法 ( 參數值 ) 範例 : document.write (test.length) 顯示字串長度

deanna
Download Presentation

認識物件

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 認識物件 Javascript內建物件分為三大類 字串物件 數學物件 日期物件 認識物件

  2. 字串物件 • 通常製造一個字串物件,最簡單的方法是指定一個文字常數給一個變數。 • 例:test=“this is a test” • 常見的屬性或方法 length bold fontsize toLowerCase toUpperCase • 使用方法 : 物件名.方法(參數值) • 範例 : document.write (test.length) 顯示字串長度 document.write (test. fontsize(20)) 顯示字串為20號字 認識物件

  3. 例題:顯示字串的方法及屬性 認識物件

  4. 程式碼 <script language="javascript"> var test ="This is a test !" document.write ("<p>"+test.length) document.write ("<p>"+test.bold()) document.write ("<p>"+test.fontsize(20)) document.write ("<p>"+test.toLowerCase()) document.write ("<p>"+test.toUpperCase()) </script> 認識物件

  5. 數學物件 • 數學物件主要是幫助你做一些數學運算。 • 例:Math.pow(2,2) => 4 • 常見的屬性或方法 abs floor max min pow sqrt random() • 使用方法 : 物件名.方法(參數值) • 範例 : document.write (Math.pow(2,2)) 2的平方為4 document.write (Math.random()) 取亂數 認識物件

  6. 日期物件 • 日期物件是來幫助你處理日期。 • 例:var d1=new Date() • 常見的屬性或方法 getDate getDay getHours getMinute getTime getYear getSeconfs getMonth 使用方法 : 物件名.方法(參數值) • 範例 : document.write (d1.getYear) 顯示年份 document.write (d1.getMonth) 顯示月份 認識物件

  7. 例題:顯示日期的方法及屬性 認識物件

  8. 程式碼 <script language="javascript"> today=new Date() date1=new Date("December 25,2004 ,11:00") date2=new Date(2004,3,18) document.write ("<p>"+today.toGMTString()) document.write ("<p>"+today.toLocaleString()) document.write ("<p>"+date1.toLocaleString()) document.write ("<p>"+date2.toLocaleString()) </script> 認識物件

More Related