2016-03-15 57 views
5

html <a></a>標記中href和data-href屬性有什麼區別? 我當前的代碼編寫如下:html中定位標記中href和data-href之間的區別

<a id="sign_in_with_facebook" href="verify_phone_process_1.html" class="btn btn-default bubbla-btn">Sign In with Facebook</a> 

,當我將其更改爲

<a id="sign_in_with_facebook" data-href="verify_phone_process_1.html" class="btn btn-default bubbla-btn">Sign In with Facebook</a> 

它不是重定向到verify_phone_process_1.html頁。

回答

4

html標記中的href和data-href屬性有什麼區別?

,前者實際上鍊接的地方,所有的功能/用戶界面,包括(因爲它是指定爲實現該屬性) - 而後者則對自己什麼都沒有,它只是一個任意命名的具有任意值的自定義數據屬性。


編輯:自定義數據的一些屬性的詳細信息:

https://developer.mozilla.org/en/docs/Web/Guide/HTML/Using_data_attributes

http://www.w3.org/TR/html5/dom.html#custom-data-attribute

+0

你可以請我建議我可以檢查這些HTML5數據屬性的任何鏈接? – Swamy

+0

我編輯了包含一些鏈接的答案,請看看。 – CBroe

+0

非常感謝.... :) :) – Swamy

5

全球HTML 數據 - *用於屬性存儲自定義數據(準備被CSS和Javascript調用)。 *是可以被任何字幕替換的通配符。

在CSS使用存儲在data-append將文本追加:after一個div的內容數據的下一個片段,而JavaScript使用存儲在data-color屬性數據在其應用背景色:

var zzz = document.getElementsByTagName("div")[0].getAttribute("data-color"); 
 
var yyy = document.getElementsByTagName("div")[1].getAttribute("data-color"); 
 

 
document.getElementsByTagName("div")[0].style.background = zzz; 
 
document.getElementsByTagName("div")[1].style.background = yyy;
div::after { 
 
    content: attr(data-append); 
 
}
<div data-append="_SUCCESS_" data-color="lawngreen"></div> 
 
<div data-append="_FAILURE_" data-color="tomato"></div>

相關問題