[英]While button is clicked my local C drive is being opened
我正在使用 HTML 做一個表單,我發現當我使用我的提交按鈕時它顯示我的本地 C 驅動器
它不提交我的表格
代碼:
<div class="container">
<form id="form" action="/">
<h1>Registration</h1>
<div class="input-control">
<label for="username">Username</label>
<input id="username" name="username" type="text">
<div class="error"> </div>
</div>
<div class="input-control">
<label for="username">Email</label>
<input id="email" name="username" type="text">
<div class="error"> </div>
</div>
<div class="input-control">
<label for="Message">Message </label>
<input id="Message" name="username" type="text">
<div class="error"> </div>
<button type="submit">Sign up</button>
</form>
在這里你可以使用這個邏輯:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<form onsubmit="sub(event)">
<input type="text" name="username" />
<input type="password" name="password" />
<button type="submit">save</button>
</form>
<script>
async function sub(ev) {
// prevents refresh
ev.preventDefault();
console.log(ev.target.username.value);
console.log(ev.target.password.value);
}
</script>
</body>
</html>
在您的<form>
標記中,您使用了一個屬性action='/'
,當您單擊提交按鈕時它會打開。 這是在文件索引或驅動器默認地址的情況下。 如果將其更改為:
<form id="form" action="#">
它不會重定向到默認地址。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.