用html做一个搜索框
时间: 2023-07-20 20:16:09 浏览: 48
好的,以下是一个简单的搜索框的 HTML 代码示例:
```html
<form action="search.php" method="get">
<input type="text" name="query" placeholder="搜索">
<button type="submit">搜索</button>
</form>
```
其中,`action` 属性指定了表单提交的地址,`method` 属性指定了提交方式,这里使用了 GET 方法。`input` 标签定义了一个文本输入框,`name` 属性指定了输入框的名称,`placeholder` 属性指定了输入框的提示文本。`button` 标签定义了一个按钮,用于提交表单。
相关问题
用HTML5做一个搜索框
<!DOCTYPE html>
<html>
<head>
<title>搜索框</title>
<meta charset="UTF-8">
<style type="text/css">
#search {
padding: 10px;
border: none;
border-radius: 5px;
width: 300px;
font-size: 16px;
}
#submit {
padding: 10px;
border: none;
border-radius: 5px;
background-color: #4CAF50;
color: white;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<form>
<input type="text" id="search" placeholder="请输入搜索内容">
<input type="submit" id="submit" value="搜索">
</form>
</body>
</html>
用html写一个搜索框
可以使用以下代码来创建一个基本的搜索框:
```html
<form action="/search" method="get">
<input type="text" name="query" placeholder="Search...">
<input type="submit" value="Search">
</form>
```
在这个示例中,我们创建了一个包含一个文本输入框和一个提交按钮的`<form>`元素。`action`属性指定了当用户提交搜索表单时将要发送的请求的URL。`method`属性指定了使用HTTP GET方法发送请求。
文本输入框使用`<input>`元素创建,并使用`type`属性设置为“text”,名称属性设置为“query”,占位符属性设置为“Search...”。提交按钮也是使用`<input>`元素创建,并使用`type`属性设置为“submit”,值属性设置为“Search”。
当用户在搜索框中输入查询并点击提交按钮时,将会向指定的URL发送一个HTTP GET请求,其中包含名为“query”的查询参数,其值为用户在搜索框中输入的文本。