facebook twitter hatena line email

「Monaca/DOM操作」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
 
(同じ利用者による、間の2版が非表示)
行28: 行28:
 
</pre>
 
</pre>
  
onload()前にhtmlを更新する処理を記述しても更新されないので注意。
+
※注意:onload()前にhtmlを更新する処理を記述しても、更新されない

2020年5月22日 (金) 11:51時点における最新版

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を更新する処理を記述しても、更新されない