【发布时间】:2020-04-28 00:21:14
【问题描述】:
我声明了一个名为“name”的变量。一旦用户单击表单,它应该调用函数 myFunction 将用户键入的值分配给变量名称。例如,如果用户键入“John”。 url 将是 localhost:5000/profile/John。但我得到 document.getElementById("username") 是未定义的。
-let name = "gg";
//- -function enteringName() {
//- - name = document.getElementById("username").value;
//- -};
<h1>Log in</h1>
<form action="/profile/#{name}" method="POST" id="loginForm" onclick="#{myFunction()}" >
<label for="username">username:</label><br />
<input type="text" id="username" name="username"/>
<br />
<label for="password">password:</label><br />
<input type="text" id="password" name="password" /><br /><br />
<input type="submit" value="Log in" />
<br />
</form>
<p>
<a href="http://localhost:3000/registration">register here</a>
</p>
<script>
function myFunction() {
-name = document.getElementById("username").value;
}
</script>
【问题讨论】:
标签: javascript pug