第十四章主要讲了 html forms,通过 forms,我们可以得到 customers' feedback,使得网页能够 interactive,本章的内容分为三个部分:

  1. forms 的 element 以及它们的 attribute.
  2. forms 进行交互的原理
  3. 如何对 forms 进行 style

How forms work?两个方面阐述

Web Server 的角度

接收

  1. 当 visitor 在一个网页上 fill out the form 并且之后 submit 了之后
  2. Browser pakages up all the data in the form and sends it over to the Web Sever.
  3. 然后Web Server 接收到之后,再将其传给里面的 Server Script 去让它 process
    ###返回
  4. Server Script 对 data 进行 process 了之后,创建一个新的 HTML 文件,然后把它传给 Web Server
  5. Web Server 得到这个 HTML 文件之后,将它再传给 Browser.
  6. 然后 Browser 得到这个界面并且 display it.

Browser 的角度

  1. 当它 encounter 到 element 的时候,开始 create 相关的 controls, 所谓的 control 是:allow you to input various kinds of data 的地方。
  2. 当 visitor fill out 了 form 之后,并且进行了 submit, Browser 将 data 进行 package up,然后将它发送给 Web Server.
  3. 最后,接收到 Web Server 返回来的文件,然后 display it.

语法以及相关的 attribute

关于<form>

形式:

<form action="http://wickedlysmart.com/hfhtmlcss/contest.php" method="POST">
/*(Everything inside the form)*/
</form>

参数:

  • action:这个 attribute 包含了 Web Server 的 URL 以及Server Script 的位置。
  • method 分为两种: POST 和 GET,
  • </form>这个 closing tag 用来 ends the form

关于 method 这个 attribute

GET :会在发送给 Web Server 之前 显示 append the data on the end of the URL ,并且你可以 bookmark 这个网址,缺点每次打开这个网址时,会 resubmited the order,所以不适用于 order 或者 密码,个人信息等网页
POST:你不能 bookmark 这个网址。但是更加安全,没有办法通过 History 查看,可以用于 密码,个人信息等网站。

form elements that create controls 关于<form>中的 element

<input>类型:

形式:<input type="" name="address">

经典的 type attribute:

  • type="text" name=""
  • type="submit":可以通过“value="Order Now""这个 attribute 来更改其显示的内容。
  • type="radio" name="hotornot" value="not"
  • type="checkbox" neme="spice[]" value="Garlic"

HTML5 中的 type attrubute:

  • type=" tel\url\e-mail ":实质上是一种 text 类型的 input ,但是在手机上显示的时候可以控制其 UI,比如显示相应的数字键盘。
  • type="number min="0" max="20" 可以设置 max 和 min 这两个 attribute 来设置其最大值和最小值,数字都为整数。
  • type="color"
  • type="range" max="0" max="20" step="5" :这个 attribute 和 number 很相似,但是是以 slider 的方式显示的,其中的 step 为一个 optional attribute.
  • type="date"

其他类型

  1. textarea <textarea name="comments" rows="10" cols="48"></textarea>用于 create a multiline text area that you can type into ,其中的 cols 和 rows 用于限制 text area 的宽度和高度。在<textarea></textarea>之间的内容鬼称为 initial text in the browser's text area control
  2. select 和 option<select><option>是一对搭档,互不分离,select 用于 create a menu control in the web page.select 用于create every menu item.它的形式是:
<select name="characters">
<option value="Buckarpp">Buckaroo Banzai</option>
<option value="Tommy">Perfect Tommy</option>
</select>

关于 name 这个 attribute

How form element "name" work:
It acts as the glue between your form and the server script that processes it.
在 Browser 向 Web Server 传递信息的过程中,Browser send the names and values to the server.

注意

  1. 这里的 name 需要注意的是:它是由 Script 所限定的,不是自定义的,写 Script 的人应该 tell you what names to use, or provide that information in the documentation for the script.
    2.<option>没有name,但是<select>有,原因在于name 的原理
  2. 对于 checkbox 和 radio 来说,由于它们 come as a set ,所以对于一系列选项来说,它们的 name 是相同的。

实际操作: Back to get those <input> into your HTML

需要注意的是:
1.<input>是一种 inline element,一方面为了美观整齐,用<br>换行;另外一方面,整个相关联的数据用<p>包括起来。

  1. <input>之前或者之后添加lable,作为表明给 visitor 的要输入的数据。

其他小知识:

  1. 如果想要在<radio><checkbox>中默认选择一项,那么就用 checked 这个 boolean attribute.
  2. 在 CSS 中可以用 table display 对 form 进行设计
  3. 其他attribute:
    placeholder\required 可以进行提示和限制必须填写,其中 required 是一个 boolean 类型的数据
    multiple 是可以在 <select>中添加的,显示的时候不再是下拉列表,而是数据的全部排列,可以使用 control 键进行多选。
    type="file"可输入文件类型数据
    type="password"可输入密码类型数据
    <fieldset>来 group together comman elements,配合使用<legend>来显示标题。 <lable for="">中的 for 这个 attribute 是 form element 中的 id 的名称,所以创建 lable 有两个步骤: 创建 element 的id
    然后创建 lable 设定 for 的值

HTML第十四章总结 HTML forms的更多相关文章

  1. JavaScript高级程序设计:第十四章

    第十四章 一.表单的基础知识 在HTML中,表单是由<form>元素来表示的,而在javascript中,表单对应的则是HTMLFormElement类型.HTMLFormElement继 ...

  2. 《Linux命令行与shell脚本编程大全》 第十四章 学习笔记

    第十四章:呈现数据 理解输入与输出 标准文件描述符 文件描述符 缩写 描述 0 STDIN 标准输入 1 STDOUT 标准输出 2 STDERR 标准错误 1.STDIN 代表标准输入.对于终端界面 ...

  3. perl 第十四章 Perl5的包和模块

    第十四章 Perl5的包和模块 by flamephoenix 一.require函数  1.require函数和子程序库  2.用require指定Perl版本二.包  1.包的定义  2.在包间切 ...

  4. Gradle 1.12 翻译——第十四章. 教程 - 杂七杂八

    有关其它已翻译的章节请关注Github上的项目:https://github.com/msdx/gradledoc/tree/1.12,或訪问:http://gradledoc.qiniudn.com ...

  5. C和指针 (pointers on C)——第十四章:预处理器

    第十四章 预处理器 我跳过了先进的指针主题的章节. 太多的技巧,太学科不适合今天的我.但我真的读,读懂.假设谁读了私下能够交流一下.有的小技巧还是非常有意思. 预处理器这一章的内容.大家肯定都用过.什 ...

  6. CSS3秘笈复习:十三章&十四章&十五章&十六章&十七章

    第十三章 1.在使用浮动时,源代码的顺序非常重要.浮动元素的HTML必须处在要包围它的元素的HTML之前. 2.清楚浮动: (1).在外围div的底部添加一个清除元素:clear属性可以防止元素包围浮 ...

  7. C#语言和SQL Server第十三 十四章笔记

    十三章  使用ADO.NET访问数据库 十四章使用ADO.NET查询和操作数据库 十三章:                                                       ...

  8. Gradle 1.12用户指南翻译——第二十四章. Groovy 插件

    其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...

  9. Gradle 1.12用户指南翻译——第三十四章. JaCoCo 插件

    本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...

随机推荐

  1. Python3 tkinter基础 Canvas coords 移动直线,itemconfig 设置矩形的颜色, delete 删除一条直线

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. RabbitMQ 入门指南——初步使用

    MQ的消息持久化 https://www.rabbitmq.com/tutorials/tutorial-two-java.html When RabbitMQ quits or crashes it ...

  3. makefile基本操作

    多数内容copy自youtube的一个视频:https://www.youtube.com/watch?v=E1_uuFWibuM 执行环境:原作者是在Linux下做的视频,而我使用的是win10,w ...

  4. sudo中的 各类授权 名称包含的操作 权限命令?

    sudo是 do something as super user: 或者说: as Super User Do something: 就是 为 "非根用户赋予根用户的权限" 使用 ...

  5. A^B mod C (快速幂+快速乘+取模)题解

    A^B mod C Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63). ...

  6. java 之 基础加强(一)

    常用快捷键: alt + / 代码提示 ctrl + / 单行注释 取消注释 ctrl + shift +/ 多行注释(先选中内容) ctrl + shift +\ 取消注释(先选中内容) ctrl ...

  7. P3244 [HNOI2015]落忆枫音

    思路 给出了一个DAG,要求以1为根的外向树的个数 如果没有加边的条件,就非常好做 每个点都只保留一条入边,最后得到的一定就是一个符合条件的树了(因为给了一个DAG啊) 所以答案是\(\prod_{i ...

  8. (转载)MySQl数据库-批量添加数据的两种方法

    方法一:使用excel表格 方法二:使用insert语句(FileWriter批量写入) 使用excel表格 1.打开数据表,按照表的字段在excel中添加数据.注意:表中字段名必须和excel中的名 ...

  9. ElasticSearch——日志工具

    Elasticsearch: 权威指南 官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.ht ...

  10. [转载]error while loading shared libraries的解決方法

    转自:https://blog.csdn.net/dumeifang/article/details/2963223 error while loading shared libraries的解決方法 ...