问题描述
我已经阅读了以前的帖子,并尝试在 HTML 中的表单元素上应用 onsubmit,但似乎仍然不起作用。我有它如下:
<form class="button" id="arrow" onsubmit='return hotelList()'>
<input type='submit' value='Submit'/>
</form>
和js:
const hotelList = () => window.location.href = './ochome.html';
有什么建议吗?谢谢
完整代码: 新问题:我的必填字段似乎不起作用,并且无论如何都会将我发送到另一个页面......
enter code here
<form action="/user-details.html" class='login'>
<!-- is this GET or POST?? -->
<label for="username" >Username</label><br>
<input class="whitebox" type="text" id='username' required/>
<label for="pass" id='pass'>Password</label><br>
<input class="whitebox" type='password' id='passBox' required/>
<input type="submit" id='arrow' value="> Submit">
</form>
解决方法
表单包含您要提交的所有输入,操作类似于:action="/file.js" 并且它必须是一个处理数据的文件
代码:
<form action="/user-details.html">
<label for="fname">First name:</label><br>
<input class="whitebox" type="text" id='username' required/>
<label for="lname">Last name:</label><br>
<input class="whitebox" type='password' id='passBox' required/>
<input type="submit" value="Submit"/>
</form>