使用html表单,您可以轻松获取用户输入。使用<form>标签来添加表单元素以获取用户输入。不同类型的表单元素包括文本输入、单选按钮输入、提交按钮等。
标签<input>通过使用type属性帮助您获取用户输入。要清除HTML表单中的所有输入,请使用带有type属性为reset的<input>标签。

以下示例演示了如何清除HTML表单中的所有输入。
在这个例子中,我们将使用document.getElementId来清除文本字段中的文本。
立即学习“前端免费学习笔记(深入)”;
<!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>Remove HTML</title>
</head>
<body>
<form>
<input type="button"
value="click here to clear"
onclick="document.getElementById('inputText').value = '' "/>
<input type="text" value="Tutorix" id="inputText" />
</form>
</body>
</html>
当我们点击清除按钮时,输入(文本区域)字段中的文本将被清除。
以下示例演示了如何清除HTML表单中的所有输入。
在这个例子中,我们将使用重置按钮来清除文本字段中的文本。
<!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>Clear all the input in HTML forms</title>
</head>
<body>
<form>
<input type="text" name="input" />
<input type="reset" value="reset" />
</form>
</body>
</html>
当我们点击清除按钮时,输入(文本区域)字段中的文本将被清除。
以下示例演示了如何清除HTML表单中的所有输入。
In this example, we are going to use onclick() method to clear the text in the text field.
<!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>Clear all the input in HTML forms</title>
</head>
<body>
<form>
<input type="text"
value="Tutorix is the best e-learning platform"
onclick="this.value=''"/>
</form>
</body>
</html>
您可以尝试运行以下代码来清除HTML表单中的所有输入 -
<!DOCTYPE html>
<html>
<body>
<form>
Student Name:<br>
<input type="text" name="sname">
<br>
Student Subject:<br>
<input type="text" name="ssubject">
<br>
<input type="reset" value="reset">
</form>
</body>
</html>
一旦点击重置按钮,表单将被清空。
以上就是如何清除HTML表单中的所有输入?的详细内容,更多请关注php中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号