我正在尝试使用html和javascript创建一个简单的问候消息,但是当用户输入他们的姓名时,hellomessage
函数应该会发生,但是什么也不会发生。
function ShowHelloMessage() {
var name = document.getElementById("myname");
document.getElementById("hellomessage").innerHTML = "Hello, " + name.value;
}
<form method="GET">
What is your name: <input type="text" size="20" id="myname" onkeydown="if (event.keyCode == 13) document.getElementById('mybutton').click()" />
<input type="text" style="display: none;" />
<button type="button" onclick="return ShowHelloMessage()" id="mybutton" class="button">Submit</button>
</form>
<div id="hellomessage"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="javascriptHP.js"></script>