HTML5 地理定位 本地儲存 拖放

2022-07-10 13:39:08 字數 1943 閱讀 1225

一、地理定位 geolocation

相容性:internet explorer 9+, firefox, chrome, safari 和 opera 支援geolocation(地理定位)。

一次性定位 getcurrentposition()

getlocation()

function

getlocation()

else

}

//成功獲取地理位置時候的**函式

function

success (position) =position.coords}//

地理位置獲取失敗時候的**函式

function

error (error)

實時定位 watchposition()

getlocation()

function

getlocation()

else

}

//成功獲取地理位置時候的**函式

function

success (position) =position.coords}//

地理位置獲取失敗時候的**函式

function

error (error)

二、web儲存

相容性:internet explorer 8+, firefox, opera, chrome, 和 safari支援web 儲存。

localstorage

1. 永久生效

2. 多視窗共享

3. 容量大約為20m

◆window.localstorage.setitem(key,value) 設定儲存內容

◆window.localstorage.getitem(key) 獲取內容

◆window.localstorage.removeitem(key) 刪除內容

◆window.localstorage.clear() 清空內容

只要在相同的協議、相同的主機名、相同的埠下,就能讀取/修改到同乙份localstorage資料。

sessionstorage

1. 生命週期為關閉當前瀏覽器視窗

2. 可以在同乙個視窗下訪問

3. 資料大小為5m左右

◆window.sessionstorage.setitem(key,value)

◆window.sessionstorage.getitem(key)

◆window.sessionstorage.removeitem(key)

◆window.sessionstorage.clear()

除了協議、主機名、埠外,還要求在同一視窗(也就是瀏覽器的標籤頁)下,就能讀取/修改。

三、拖放

相容性:internet explorer 9+, firefox, opera, chrome, 和 safari 支援拖動,但safari 5.1.2不支援拖動。

分析:分成兩部分,一部分是被拖動的元素,另一部分是接收拖動元素的區域元素

被拖動元素:

draggable 屬性設定為 true

ondragstart 屬性呼叫了乙個函式drag(event)

接收拖動元素的區域元素:

ondragover 屬性事件規定在何處放置被拖動的資料 event.preventdefault()

ondrop 屬性呼叫了乙個函式drop(event)

移動我哦

HTML5之本地儲存

html5之本地儲存 l cookie 資料儲存到計算機中,通過瀏覽器控制新增與刪除資料 l cookie的特點 儲存限制 網域名稱100個cookie,每組值大小4kb 客戶端 伺服器端,都會請求伺服器 頭資訊 本地儲存也會請求伺服器 頁面間的cookie是共享 l storage session...

HTML5之本地儲存

html5本地儲存有localstorage和sessionstorage,兩者的區別就是localstorage一直儲存在本地不會過期,而sessionstorage視窗一旦關閉就沒了。兩者用法是一樣的。if window.localstorage else儲存操作如下 通過鍵值對應,只能儲存字串...

HTML5的本地儲存

html5的本地儲存分為永久性的本地儲存和會話性的本地儲存。會話性本地儲存sessionstorage 儲存在sessionstorage中的資料首先是key value形式的,另外就是它跟瀏覽器當前會話相關,當會話結束後,資料會自動清除,跟未設定過期時間的cookie類似。setitem key,...