创建一个表单,可输入账号(文本框)和密码( 密码框), 点击提交按钮,可以提交到reg.html页面(显示注册成功), 点击重置按钮可以恢复表单的初始状态。
时间: 2024-01-12 11:03:09 浏览: 42
好的,可以通过以下HTML和JavaScript代码实现:
```html
<!-- form.html -->
<form id="myForm" action="reg.html" method="post">
<label for="username">账号:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required><br><br>
<button type="submit">提交</button>
<button type="reset" onclick="resetForm()">重置</button>
</form>
<script>
function resetForm() {
document.getElementById("myForm").reset(); // 通过reset()方法重置表单
}
</script>
```
这段代码创建了一个表单,包含一个文本框和一个密码框,一个提交按钮和一个重置按钮。当点击提交按钮时,表单数据会提交到reg.html页面。当点击重置按钮时,表单会被重置为初始状态。JavaScript代码中的resetForm()函数会调用表单的reset()方法来实现表单重置的功能。
相关问题
在PHP 中的表单控件中,创建一个表单,包含文本框、密码框和 提交按钮。
可以使用以下 PHP 代码创建一个包含文本框、密码框和提交按钮的表单:
```php
<!DOCTYPE html>
<html>
<head>
<title>表单示例</title>
</head>
<body>
<form action="submit.php" method="post">
<label for="username">用户名:</label>
<input type="text" name="username" id="username"><br><br>
<label for="password">密码:</label>
<input type="password" name="password" id="password"><br><br>
<input type="submit" value="提交">
</form>
</body>
</html>
```
在上述代码中,我们创建了一个包含两个标签的表单:一个文本框和一个密码框。`<label>` 标签用于指定文本框和密码框的标签名称,`<input>` 标签用于创建文本框和密码框。我们还创建了一个提交按钮,当用户单击该按钮时,表单将提交到 `submit.php` 页面进行处理。
你可以将上述代码保存为 `form.php` 文件,并在浏览器中打开该文件,以查看创建的表单。
用html5创建一个登录界面,要包含文本框,密码框和提交按钮
可以使用以下代码在HTML5中创建一个简单的登录界面,包含文本框、密码框和提交按钮:
```html
<!DOCTYPE html>
<html>
<head>
<title>登录</title>
</head>
<body>
<h2>登录</h2>
<form action="#" method="post">
<label for="username">用户名:</label>
<input type="text" id="username" name="username"><br><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="提交">
</form>
</body>
</html>
```
在上面的代码中,我们使用了HTML5的form元素来创建一个表单,包含一个文本框和一个密码框。表单的提交按钮使用了input元素的type属性设置为submit。当用户单击提交按钮时,表单数据将被提交到action属性所指定的URL地址中,这里我们将action设置为"#"表示提交到当前页面。