1
これは私が今までにいくつかの警告と私の最初の投稿から除外した最初のjavascriptです。だから私は、HTMLページと外部のjavascriptファイルを作成しました。両方のファイルは同じディレクトリにあり、私は各ファイルのスペルを確認しています。ここでJavascriptの外部ファイルが正しくリンクされていません
はhtmlコードです:
<body>
<p>Press the buttons to change the box!</p>
<div id="box" style="height:150px; width:150px; background-color:orange; margin:25px"></div>
<button id="button1" onclick="divGrow">Grow</button>
<button id="button2" onclick="divColor">Blue</button>
<button id="button3" onclick="divFade">Fade</button>
<button id="button4" onclick="divReset">Reset</button>
<script type="text/javascript" src="javascript.js"></script>
</body>
、ここではjavascriptのファイルです:
function divGrow() {
alert("This grows the box");
document.getElementById("box").style.width = "300px";
document.getElementById("box").style.height = "300px";
}
function divColor() {
alert("This changes the Box to Blue");
document.getElementById("box").style.backgroundColor = "Blue";
}
function divFade() {
alert("This fades the box");
document.getElementById("box").style.opacity = ".5";
}
function divReset() {
alert("This resets the box")
document.getElementById("box").style.backgroundColor = "Orange"
document.getElementById("box").style.width = "150px";
document.getElementById("box").style.height = "150px";
document.getElementById("box").style.opacity = "0";
}
私は別のリンク足りませんか? JavaScriptコードを動作させるには?
あなたがエラーの(http://stackoverflow.com/documentation/javascript/185/hello-world/714/using-console-log)[コンソールをチェックする]がありますか? –