我想在點擊從「開始」到「重新啓動」時更改按鈕的標籤。我的應用程序將以多種語言提供,我正在使用L10n.js庫。按鈕的標籤可以有緊跟在app.properties定義2點的值(「開始」和「重新啓動」)):當data-l10n-id屬性發生變化時,innerhtml的值不會改變
start = Start
restart = Restart
text = this is some text
another-text = this is another text
按鈕的定義如下(使用按鈕積木):
<body>
<p id="sometext" data-l10n-id="text"></p>
<section data-type="sidebar" role="region" class="skin-dark">
<section style="margin-bottom: 30px">
<button id="startbutton" class = "recommend" data-l10n-id="start">Start</button>
</section>
</div>
</section>
一旦頁面被加載正確的按鈕(和段)值顯示。該數據本地化-id屬性和對應的值應該在點擊更改:
document.getElementById("startbutton").addEventListener("click", function(event) {
this.setAttribute("data-l10n-id", "restart");
document.getElementById("sometext").setAttribute("data-l10n-id", "another-text");
});
看着DOM屬性已經改變,但不是值應該顯示:
<p id="sometext" data-l10n-id="another-text">this is some text</p>
<section data-type="sidebar" role="region" class="skin-dark">
<section style="margin-bottom: 30px">
<button id="startbutton" class="recommend" data-l10n-id="restart">Start</button>
</section>
</section>
有什麼我做錯誤?歡迎任何評論!謝謝。
您正在使用哪個版本的Firefox OS進行測試? – thomas