Monaca/DOM操作
提供: 初心者エンジニアの簡易メモ
html書き換え
index.html
<head>
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("PhoneGap is ready");
}
</script>
</head>
<body onload="init();" id="stage" class="theme">
<div id="helloid1">Helloid1</div>
<div class="helloclass1">Helloclass1</div>
main.js
function init() {
document.addEventListener("deviceready", deviceInfo, true);
}
var deviceInfo = function() {
// idのタグを更新
document.getElementById("helloid1").innerHTML = "Helloid2";
// classのタグを更新(何故か、こちらは更新されなかった)
document.getElementsByClassName("helloclass1").innerHTML = "helloclass2";
};
注意) onload()前にhtmlを更新する処理を記述しても更新されないので
