美文网首页
HTML基础(3)

HTML基础(3)

作者: 忘不了oh | 来源:发表于2017-08-10 15:55 被阅读0次

表单元素

表单是一个包含表单元素的区域,表单元素是允许用户在表单中输入内容,比如:文本域(textarea)、下拉列表、单选框(radio-buttons)、复选框(checkboxes)等等.所有的表单内容,都要写在form标签里面.

<form>
 所有的表单内容,都要写在form标签里面
</form>

input标签

input标签有一个type属性, 这个属性有很多类型的取值, 取值的不同就决定了input标签的功能和外观不同.

文本域

  • 明文输入框:用户可以在输入框内输入内容
    账号:<input type="text"/>
  • 暗文输入框:用户可以在输入框内输入内容
    密码:<input type="password"/>
  • 给输入框设置默认值
    账号:<input type="text" value="123"/>
    密码:<input type="password" value="123"/>
    <input type="text" placeholder="坚持就是胜利">
    placeholder 属性提供可描述输入字段预期值的提示信息,该提示会在输入字段为空时显示,并会在字段获得焦点时消失
  • 规定输入字段中的字符的最大长度
    账号: <input type="text" name="fullname" maxlength="8" />

多行文本域

<textarea cols="30" rows="10">默认</textarea>

  • cols属性表示columns“列”, 规定文本区内的可见宽度
  • rows属性表示rows“行”, 规定文本区内的可见行数
  • 默认情况下输入框是可以手动拉伸的,可以用css中的resize为none来固定

按钮

单选按钮(Radio Buttons)
<input type="radio" name="xingbie" /> 男
<input type="radio" name="xingbie" /> 女
<input type="radio" name="xingbie" /> 妖

notice:单选按钮,天生是不互斥的,如果想互斥,必须要有相同的name属性.

复选框(Checkboxes)
<input type="checkbox" name="aihao" checked="checked"/> 篮球
<input type="checkbox" name="aihao" checked="checked"/> 足球
<input type="checkbox" name="aihao"/> 棒球

notice:复选框,最好也是有相同的name(虽然他不需要互斥,但是也要有相同的name)

提交按钮(Submit Button)

定义提交按钮.提交按钮会把表单数据发送到action属性指定的页面

<input type="submit" />
notice:

  • 这个按钮不需要写value自动就有“提交”文字
  • 要想通过submit提交数据到服务器, 被提交的表单项都必须设置name属性
  • 默认明文传输(GET)不安全, 可以将method属性设置为POST改为非明文传输(学到Ajax再理解)
重置按钮(Reset Button)

定义重置按钮.点击之后会将重置按钮所在的表单中填写的内容清空.

<input type="reset">

label标签

label标签不会向用户呈现任何特殊效果.不过,它为鼠标用户改进了可用性.
方法一:

<!--给文本框添加绑定-->
<label for="account">账号:</label>
<input type="text" id="account" />
<!--给单选框添加绑定-->
<input type="radio" name="sex" id="man" /> <label for="man">男</label>
<!--给多选框添加绑定-->
<input type="checkbox" id="basketball" />
<label for="basketball">篮球</label>

表单元素要有一个id,然后label标签就有一个for属性,for属性和id相同就表示绑定了,所有表单元素都可以通过label绑定.
方法二:

<label>
账号:<input type="text">
</label>
<label >
密码:<input type="password">
</label>

直接用label标签包裹.

数据列表

作用:给输入框绑定待选项

datalist>
  <option>待选项内容</option>
</datalist>

如何给输入框绑定待选列表

  • 搞一个输入框
  • 搞一个datalist列表
  • 给datalist列表标签添加一个id
  • 给输入框添加一个list属性,将datalist的id对应的值赋值给list属性即可
请输入你的车型: <input type="text" list="cars">
<datalist id="cars">
    <option>奔驰</option>
    <option>宝马</option>
    <option>奥迪</option>
    <option>路虎</option>
    <option>宾利</option>
</datalist>
QQ截图20170810152328.png

下拉列表

作用: select标签和ul、ol、dl一样,都是组标签. 用于创建表单中的待选列表, 可以从选择某一个带选项

选择籍贯:
<select>
  <option selected="selected">北京</option>
  <option>河北</option>
  <option>河南</option>
  <option>山东</option>
  <option>山西</option>
  <option>湖北</option>
  <option>贵州</option>
</select>

给下拉列表添加分组

<select>
  <optgroup label="北京市">
      <option>海淀区</option>
      <option>昌平区</option>
      <option>朝阳区</option>
  </optgroup>
      <optgroup label="广州市">
      <option>天河区</option>
      <option>白云区</option>
  </optgroup>
</select>

notice:

  • 下拉列表不能输入内容,但是可以直接在列表中选择内容
  • 可以通过给option标签添加一个selected属性来默认指定列表的默认值
  • 可以通过给option包裹一层optgroup标签来给下拉列表的内容分类

fieldset标签

作用:可以给表单添加一个边框,legend标签可以为边框指定一个标题

<form>
        <fieldset>
        <legend>表单练习</legend>
        <label>
            账号:<input type="text"><br>
        </label>
        <label>
            密码:<input type="password"><br>
        </label>
        性别:
        <input type="radio" id="man" name="name">
        <label for="man">男</label>
        <input type="radio" id="girl" name="name">
        <label for="girl">女</label>
        <input type="radio" id="secrit" name="name" checked="checked">
        <label for="secrit">保密</label><br>
        爱好: 
        <input type="checkbox" id="basketball">
        <label for="basketball">男球</label>
        <input type="checkbox" id="baseball">
        <label for="baseball">足球</label>
        <input type="checkbox" id="xxoo" checked="checked">
        <label for="xxoo">足浴</label><br>
        <label for="introduce">个人简介</label>
        <textarea name="" id="introduce" cols="30" rows="10"></textarea><br>
        <label for="birthday">生日</label>
        <input type="date" id="birthday"><br>
        <label for="email">邮箱</label>
        <input type="email" id="email"><br>
        <label for="mobile">手机</label>
        <input type="number" id="mobile"><br>
        <label for="urle">域名</label>
        <input type="url" id="urle"><br>
        <label for="times">时间</label>
        <input type="date" id="times"><br>
        <label for="col">颜色</label>
        <input type="color" id="col"><br>
        <input type="submit" value="注册">&nbsp;&nbsp;&nbsp;
        <input type="reset" value="清空"><br>
    </fieldset>
</form>
QQ截图20170810154934.png

相关文章

  • 前后端学习教程汇总

    前端学习路径教程 HTML 基础 HTML基础:https://www.w3school.com.cn/html/...

  • HTML基础(3)

    表单元素 表单是一个包含表单元素的区域,表单元素是允许用户在表单中输入内容,比如:文本域(textarea)、下拉...

  • HTML 基础-3

    本教程版权归饥人谷_佩佩216和饥人谷所有,转载须说明来源. line-height有什么作用?css 标签,用于...

  • HTML 基础 3

    line-height有什么作用? 设定行高,文本默认上下居中line-height示例 如何去查CSS属性的兼容...

  • HTML基础(3)

    饥人谷学习第3天 HTML 超文本标记语言,是一个可以用来结构化Web内容并给予其含义和目标的编码语言。 概览 D...

  • HTML5入门

    html基础-认识html 1.html的基本结构 2. DTD文档声明 3...

  • w3c School读书笔记(一):HTML基础

    html的基础知识 w3c_html基础教程总结 文档的基本结构 脑图 常见元素 HTML元素语义的分类 结构类 ...

  • 学习前端需要掌握什么基础?

    学习前端需要掌握什么基础?前端基础包含HTML、CSS层叠样式表、JavaScript、HTML5、CSS3、jQ...

  • 前端基础总结:HTML基础知识

    HTML基础知识 1、HTML的历史:HTML,XHTML 2、HTML的全局属性:全局标准属性,全局事件属性 3...

  • HTML:基础(3)属性

    HTML 属性 属性是 HTML 元素提供的附加信息。 HTML 属性 HTML 元素可以设置属性 属性可以在元素...

网友评论

      本文标题:HTML基础(3)

      本文链接:https://www.haomeiwen.com/subject/dpdhrxtx.html