前端知识之HTML-----form------from表单属性 傷城~ 2022-06-08 02:50 195阅读 0赞 form即为表单,是一个专门让用户输入数据或者选择的一个组件。 格式: <form> 记住,所有表单内容都要写在表单里面 </form> //form中主要有两个属性:action和method # 1.表单form内属性 # ## 1.1 action属性 ## action是表单提交的地址,是一个必须的属性,他规定当提交表单时,向何处发送表单数据。 1.格式:`<form action="value">` 2.属性值,即value的值:URL(可以是绝对地址,也可以是相对地址) 例如 绝对 URL - 指向其他网站(比如 src="www.baidu.com/search.htm") 相对 URL - 指向站点内的文件(比如 src="search.htm") //文件可以是jsp,asp,html等等 ## 1.2 method属性 ## method是规定如何发送表单数据,即以什么方式将数据发送到action指定的页面 格式:URL 变量(method="get") HTTP post (method="post") 下面详细说说两种方式又什么区别: * get: 浏览器会与处理表单的服务器取得联系,然后通过一个传输步骤将数据传输到服务器。 浏览器会直接将数据附在表单的action URL之上,中间用?隔开,多个数据由&隔开 www.baidu.com/search?param=ant¶m=black www.baidu.com/search?param1=ant¶m2=black www.baidu.com/search?param=ant,black //要注意&是字符实体的插入符号,可能会正好对应某个实体字符,所以应尽量使用&(代表&)或者 //使用&来替换,这样会有效减少错误率 //这是三种提交数据的方式,均可,后台有对应的方法方式接受数据 //详看另外一篇博客springMVC接受数据的方式 [springMVC接受数据的方式 ][springMVC_] * post 使用这种方式时流程是这样的: 浏览器和action指定的服务器取得联系,然后以分段传输的方式将数据发送给服务器---- -----服务器从一个特定的标志位读取数据,然后使用特定的解码方式进行解码,再获得参数。 HTTP 请求分为三个部分:状态行、请求头、消息主体 POST 提交的数据必须放在消息主体(entity-body)中,又因为服务器会根据请求头中的Content-Type来知道post是以何种方式进行编码的,再去解析,所以这里将讲到Content-type和entity-body两部分。POST的请求方式主要有以下四种 <table> <thead> <tr> <th align="center">请求方式</th> <th align="center">特点</th> </tr> </thead> <tbody> <tr> <td align="center">application/x-www-form-urlencoded</td> <td align="center">最常见的 POST 提交数据的方式,浏览器原生form会自动按照这种方式提交</td> </tr> <tr> <td align="center">multipart/form-data</td> <td align="center">使用表单上传文件时,必须让 form 的 enctyped 等于这个值,一般用来上传文件</td> </tr> <tr> <td align="center">application/json</td> <td align="center">告诉服务端消息主体是序列化后的 JSON 字符串</td> </tr> <tr> <td align="center">text/xml</td> <td align="center">使用 HTTP 作为传输协议,XML 作为编码方式的远程调用规范</td> </tr> </tbody> </table> * post和get的对比 <table> <thead> <tr> <th align="center">GET</th> <th align="center">POST</th> </tr> </thead> <tbody> <tr> <td align="center">后退无害</td> <td align="center">后退重新提交</td> </tr> <tr> <td align="center">只允许 ASCII 字符</td> <td align="center">无数据类型限制</td> </tr> <tr> <td align="center">有长度限制</td> <td align="center">无长度限制</td> </tr> <tr> <td align="center">有历史记录</td> <td align="center">无历史记录</td> </tr> <tr> <td align="center">有缓存</td> <td align="center">无缓冲</td> </tr> <tr> <td align="center">安全性低</td> <td align="center">安全性高</td> </tr> <tr> <td align="center">可见</td> <td align="center">不可见</td> </tr> </tbody> </table> ## 3.id ## 表单的唯一属性 ## 4.name: ## 表单的名字 ## 5.表单的完整属性 ## <form id="login" name="login" method ="Post" action="Post.aspx"> <form id="login" name="login" method ="Get" action="www.baidu.com/search?param=ant¶m=black"> [springMVC_]: http://blog.csdn.net/zzg19950824/article/details/77942255
还没有评论,来说两句吧...