繁体   English   中英

单击按钮时,我的本地 C 驱动器正在打开

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM