2013-05-21 44 views
4
數據圖標

我有我的HTMLSetting元素使用JavaScript

<button id="play-pause" aria-hidden="true"></button> 

以下按鈕元素在jQuery的ready事件,我運行下面的代碼:

$('#play-pause').attr('data-icon', '&#xe00a;') 

這會將HTML元素這個

<button id="play-pause" aria-hidden="true" data-icon="&#xe00a;"></button> 

其中在瀏覽器呈現這樣的(鉻穩定):

play pause button

但是,如果我刪除的JavaScript代碼,請手動將HTML更改爲以下(這是同樣的事情作爲JS WAAS做),並刷新頁面:

<button id="play-pause" aria-hidden="true" data-icon="&#xe00a;"></button> 

那麼它呈現像這樣:

play pause button rendered properly

有什麼區別?

我懷疑這是無關緊要的,但這裏的CSS:

/* Use the following CSS code if you want to use data attributes for inserting your icons */ 
[data-icon]:before { 
    font-family: '45sound'; 
    content: attr(data-icon); 
    speak: none; 
    font-weight: normal; 
    font-variant: normal; 
    text-transform: none; 
    line-height: 1; 
    font-style:normal; 
} 
+0

您使用jQuery UI的按鈕? –

回答

6

使用Unicode值:

$('#play-pause').attr('data-icon', '\uE00A'); 
+1

啊..當然。天色已晚。 –