在 HTML 中的输入类型=文本之间删除



这是一个简单的表单,它收集用户的信息并将该信息发送到指定的电子邮件地址。但是每当我将这些信息提取到邮件中时,&就会出现在输入之间。喜欢

email=some%40gmail.com&password=asdf&password-repeat=asdf

如何删除它?请帮忙

这是我的HTML表单:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form method="post" action="mailto:somebody@gmail.com">
<div class="container">
<h1>Register</h1>
<p>Please fill in this form to create an account.</p>
<hr>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>
<label for="password"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" required>
<label for="password-repeat"><b>Repeat Password</b></label>
<input type="password" placeholder="Repeat Password" name="password-repeat" required>
<hr>
<p>By creating an account you agree to our <a href="#">Terms & Privacy</a>.</p>
<button type="submit" class="registerbtn">Register</button>
</div>
<div class="container signin">
<p>Already have an account? <a href="#">Sign in</a>.</p>
</div>
</form>
</body>
</html>

有两种方法可以做到这一点:

1( 在<form>标签中添加enctype="text/plain",例如:

<form method="post" enctype="text/plain" action="mailto:alice@example.com">

2( 将formenctype="text/plain"添加到<button>标签中,例如:

<button type="submit" formenctype="text/plain" class="registerbtn">Register</button>

这两种方法都会产生如下正文:

email=bob@example.com
password=asdf
password-repeat=asdf

这是必需的,因为表单的默认 MIME 类型为application/x-www-form-urlencoded。您可以在 Mozilla.org 阅读更多相关信息。我在下面引用了enctype,但提供了两者的链接。

目录

当方法属性的值为 post 时,enctype 是用于将表单提交到服务器的 MIME 类型的内容。可能的值为:

  • application/x-www-form-urlencoded:如果未指定属性,则为默认值。
  • multipart/form-data:用于类型属性设置为"file"的<input>元素的值。
  • text/plain(HTML5(

此值可以由<button><input>元素上的 formenctype 属性覆盖。

  • 参考: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-enctype
  • 参考: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-formenctype

这是您的代码(带有演示电子邮件地址(作为enctype的运行示例:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form method="post" enctype="text/plain" action="mailto:alice@example.com">
<div class="container">
<h1>Register</h1>
<p>Please fill in this form to create an account.</p>
<hr>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>
<label for="password"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" required>
<label for="password-repeat"><b>Repeat Password</b></label>
<input type="password" placeholder="Repeat Password" name="password-repeat" required>
<hr>
<p>By creating an account you agree to our <a href="#">Terms & Privacy</a>.</p>
<button type="submit" class="registerbtn">Register</button>
</div>
<div class="container signin">
<p>Already have an account? <a href="#">Sign in</a>.</p>
</div>
</form>
</body>
</html>

最新更新