HTML本体から呼び出されたときにJavaScript関数が応答しません。 私は、関数sayHi()
が定義されていないというエラーが発生し続けます。エラーが発生しました - sayHi()が定義されていません、わかりません
<head>
<meta charset="UTF-8">
<title>innerHTML.html</title>
<script type = "text/javasctipt">
// javasctipt
function sayHi(){
txtName = document.getElementById("txtName");
divOutput = document.getElementById("divOutput");
var name = txtName.value;
divOutput.innerHTML = "<em>" + name + "</em>";
divOutput.innerHTML += " is very nice name.";
}
</script>
</head>
<body>
<h1>Inner HTML Demo</h1>
<form action = "">
<fieldset>
<label>Please type your name</label>
<input type = "text"
id = "txtname" />
<button type = "button"
onclick = "sayHi()" >
Click Me
</button>
</fieldset>
</form>
<div id = "divOutput">
Watch this space
</div>
</body>
</html>
HTMLに入力ミスがあります。 'txtname'は' txtName'で、 'text/javasctipt'は' text/javascript'でなければなりません。 – 4castle