html基础标签——form
2020-05-07 本文已影响0人
LeslieFind
效果:

说明:实现了一个向输入框输入关键词,点击搜索后,自动跳转百度对改关键词的搜索结果

代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="https://www.baidu.com/s" method="get" enctype="multipart/form-data">
搜索词:<input type="text" name="wd"/>
<input type="submit" value="搜索"/>
</form>
</body>
</html>
总结:
1、form的作用:我个人的理解是把这个标签下的内容一起进行提交
2、属性action:提交后接下来的动作,结合input一起使用,input标签内的name属性值为提交数据的key,浏览器在输入框的内容为提交数据的value,以上述为例,提交表单后,会接收wd=“测试”的数据
3、属性method:若action是个http请求,需要定义method是get/post请求
4、属性enctype:先记住上传文件时必须有enctype="multipart/form-data"