「Monaca/DOM操作」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→html書き換え) |
(→html書き換え) |
||
行2: | 行2: | ||
==html書き換え== | ==html書き換え== | ||
index.html | index.html | ||
− | + | <pre> | |
+ | <head> | ||
<script> | <script> | ||
document.addEventListener("deviceready", onDeviceReady, false); | document.addEventListener("deviceready", onDeviceReady, false); | ||
行9: | 行10: | ||
} | } | ||
</script> | </script> | ||
− | + | </head> | |
− | + | <body onload="init();" id="stage" class="theme"> | |
− | + | <div class="helloclass1">Helloclass1</div> | |
− | + | <div id="helloid1">Helloid1</div> | |
+ | </pre> | ||
main.js | main.js |
2020年5月22日 (金) 11:36時点における版
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 class="helloclass1">Helloclass1</div> <div id="helloid1">Helloid1</div>
main.js
function init() { document.addEventListener("deviceready", deviceInfo, true); } var deviceInfo = function() { document.getElementById("helloid1").innerHTML = "Helloid2"; document.getElementsByClassName("helloclass1").innerHTML = "helloclass2"; console.log("hello=" + document.getElementById("helloid").innerHTML); };
タグ内のidのtext取得
<p id="hello1">Hello1</p> <script> console.log(document.getElementById("hello1").textContent); // Hello1 </script>
タグ内のclassのtext取得
<p class="hello2">Hello2</p> <script> console.log(document.getElementsByClassName("hello2").textContent); // Hello1 </script>