HTML续2
HTML续
一些标签总结
跳转页面
- a 发起get请求
- form 发起post请求(默认get但是谁这么无聊)
回忆知识点:get是获取内容,post是上传内容
form 标签
- 如果form 里没有提交按钮就无法提交,除非你用JS
- method 请求方式(没人用get)只有两个值 get/post
- action 请求路径
1 | <form action="index2.html" method="post"> |
如上你点击提交后我们在chrome里点击Network
如果提交的是中文,就把对应字符的UTF-8编码每个字节分开并加一个%
1 | Content-Type: application/x-www-form-urlencoded |
问题1 form 标签在哪些情况下可以被用户提交
- form 标签里面有一个 input type=submit 的元素
- form 标签里面有一个 button 元素,button 的 type 属性为空
详细讲一下第二种
form里存在一个button它会升级为提交按钮
1 | <form action="index2.html" method="post"> |
- 如果你添加了 type=”button” 就无法提交
1 | <button type="button">提交</button> |
- 如果你是 input的button也是无法提交的
1 | <input type="button" value="提交"> |
问题2 form 标签里面的 input 加不加 name 属性由什么区别?
如果 input 不加 name,那么在表单提交时,input 的值就不会出现在请求里
form与 a标签一样 也有target属性
行为同 a标签一样 具体看上一篇博客
- _blank
- _slef
- _parent
- _top
checkbox
问题1 有时候你想点击「免单」也会勾选此时发现无法勾选
- 给input添加id=”xxx”
- 给触发的文本套上 label标签并指定 for=”xxx”
1 | <input type="checkbox">免单 |
老司机应该这样,直接用label把整体包起来
1 | <label>账号<input type="text" name="username"></label> |
问题2 如果是多个复选框
你应该让它们的name相同
1 | <label><input type="checkbox" name="fruit" value="apple">苹果</label> |
radio 单选框
1 | <label><input type="radio" name="gender" value="man">男</label> |
select 下拉选
如果想多选请添加 multiple属性
1 | <select name="local"> |
textarea 文本域
- 默认它可以拖动的 要用style控制 resize:none;
- 建议用CSS控制它的宽高
- 它提供的cols和rows是不准的 列和行设置
1 | <textarea name="" cols="30" style="resize:none;"rows="10"></textarea> |
table 标签 (用的很少)
1 | <table> |
table之慎用标签 colgroup col
之所以慎用,就因为2017年11月某天我知道它的用法然后就用了,结果导致一个bug(firefox里不支持这个标签#仅对应2017年11月那个我使用的firefox版本)
1 | <table border=1> |
PS建议控制 td 样式还是追随大众使用 class
thead tbody tfoot如果顺序错了会咋样
不管你怎样放置它们的顺序,即使F12里查到对应标签顺序是你写的顺序,但是浏览器会自动纠错依然会以thead tbody tfoot的顺序展现在表格上
不写thead/tfoot 会咋样
没有问题
不写tbody会咋样
它会自动帮你生成tbody 并把 tr放在里面
最后说一下默认表格设置了边框是很丑的,一般要设置边框融合
1 | table{border-collapse:collapse} |