「JavaScript」グローバルスコープ(Global Scope)の変数を使うサンプル
書式
var 変数名
function 関数名(){ 変数名}
使用例
<!DOCTYPE html>
<html>
<body>
<div id="cft"></div>
<script>
var strName = "567";
testFunction();
function testFunction() {
document.getElementById("cft").innerHTML = "test" + strName;
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<div id="cft"></div>
<script>
var strName = "567";
testFunction();
function testFunction() {
document.getElementById("cft").innerHTML = "test" + strName;
}
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <div id="cft"></div> <script> var strName = "567"; testFunction(); function testFunction() { document.getElementById("cft").innerHTML = "test" + strName; } </script> </body> </html>