2017-05-05 155 views
0

我試圖找出battlelog如何管理從內部邊緣瀏覽器中啓動本地應用程序,發現如下:如何將自定義屬性添加到標準HTML元素?

<button class="btn btn-primary" data-intro-step="4" data-bind-action="matchmake-mp-role" data-track="playnow.matchmake.cqclassic.join" data-bind-intro="next" data-expansion="0" data-game="2048" data-platform="1" data-role="1" data-experience="1"> 
Play now 
</button> 

請幫我瞭解這些屬性,如數據綁定行動等已添加按鈕元素以及它們如何被處理?

+2

看到這個https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes – prasanth

+0

如果你想使用jquery,請看這個https://api.jquery.com/jquery.data/ –

+0

自定義屬性只是將*有效*數據存儲在沒有固有含義或視覺屬性的DOM元素中的一種方式。如何添加它們以及它們如何被使用(或處理)不能僅由您顯示的HTML來確定。 – illiteratecoder

回答

-2

data-*屬性是自定義屬性;它們僅用於存儲Web開發人員在JavaScript中使用代碼的特定數據。

<button id="mybutton" class="btn btn-primary" data-intro-step="4" data-bind-action="matchmake-mp-role" data-track="playnow.matchmake.cqclassic.join" data-bind-intro="next" data-expansion="0" data-game="2048" data-platform="1" data-role="1" data-experience="1"> 
Play now 
</button> 

例如訪問來自jquery的所述data-intro-step值,開發者可以鍵入$('#mybutton').attr('data-intro-step')$('#mybutton').data('data-intro-step')並在他的代碼somethiing使用它。

通常它們是從php或js框架添加的,如jquery-pluginsangularjs,並用於js。把你也可以添加他們從js以後使用它。

+1

「data- *屬性不是標準」 - [它是標準](https://www.w3.org/TR/html5/dom.html#embedding-custom-non-visible-data-with-數據 - * - 屬性) – Quentin

+0

「通常他們是從PHP添加」 - 這是一個非常狹窄的世界觀。 – Quentin

相關問題