表单部件

通用属性

属性名称描述
atuofocus页面加载时自动具有输入焦点
disabled失效,用户不能交互
name元素名称,跟表单数据提交,参数中的key
value元素的初始值,参数中的value
文本输入框

readonly:只读
placeholder:占位符,描述
输入的最大字符数

  • 单行文本框
  • E-mail地址框
    multiple:多个地址以逗号分隔
  • 密码框
    在安全连接上托管任何涉及表单的页面
  • 搜索框
    值可以被自动保存用来在同一站点上的多个页面上自动补全。
  • 电话号码栏
  • URL栏
  • 多行文本框textarea
    允许用户输入包含硬换行符
    右下角拖放操作可有resize为none关闭
属性名描述
cols字符宽度
rows文本行数
下拉内容

属性:selected

  • 选择框
<select id="groups" name="groups">
  <optgroup label="fruits">
    <option>Banana</option>
    <option selected>Cherry</option>
    <option>Lemon</option>
  </optgroup>
  <optgroup label="vegetables">
    <option>Carrot</option>
    <option>Eggplant</option>
    <option>Potato</option>
  </optgroup>
</select>

在这里插入图片描述

  • 多选选择框
<select multiple id="multi" name="multi">
  <option>Banana</option>
  <option>Cherry</option>
  <option>Lemon</option>
</select>

不是下拉列表
在这里插入图片描述

  • 自动补全输入框
 <label for="myFruit">What's your favorite fruit?</label>
            <input type="text" name="myFruit" id="myFruit" list="mySuggestion">
            <datalist id="mySuggestion">
              <option>Apple</option>
              <option>Banana</option>
              <option>Blackberry</option>
              <option>Blueberry</option>
              <option>Lemon</option>
              <option>Lychee</option>
              <option>Peach</option>
              <option>Pear</option>
            </datalist>

在这里插入图片描述

可选中项

属性
checked:默认被选中
value:默认为on

  • 复选框
<fieldset>
          <legend>Choose all the vegetables you like to eat</legend>
          <ul>
            <li>
              <label for="carrots">Carrots</label>
              <input type="checkbox" checked id="carrots" name="carrots" value="carrots">
            </li>
            <li>
              <label for="peas">Peas</label>
              <input type="checkbox" id="peas" name="peas" value="peas">
            </li>
            <li>
              <label for="cabbage">Cabbage</label>
              <input type="checkbox" id="cabbage" name="cabbage" value="cabbage">
            </li>
            <li>
              <label for="cauli">Cauliflower</label>
              <input type="checkbox" id="cauli" name="cauli" value="cauli">
            </li>
            <li>
              <label for="broc">Broccoli</label>
              <input type="checkbox" id="broc" name="broc" value="broc">
            </li>
          </ul>
        </fieldset>

在这里插入图片描述

  • 单选按钮
 <fieldset>
          <legend>What is your favorite meal?</legend>
          <ul>
            <li>
              <label for="soup">Soup</label>
              <input type="radio" checked id="soup" name="meal" value="soup">
            </li>
            <li>
              <label for="curry">Curry</label>
              <input type="radio" id="curry" name="meal" value="curry">
            </li>
            <li>
              <label for="pizza">Pizza</label>
              <input type="radio" id="pizza" name="meal" value="pizza">
            </li>
            <li>
              <label for="tacos">Tacos</label>
              <input type="radio" id="tacos" name="meal" value="tacos">
            </li>
            <li>
              <label for="bolognaise">Bolognaise</label>
              <input type="radio" id="bolognaise" name="meal"  value="bolognaise">
            </li>
          </ul>
        </fieldset>

在这里插入图片描述

按钮
  • submit
  • reset
  • anonymous
 <p>
          <button type="submit">
            This a <br><strong>submit button</strong>
          </button>
        </p>
        <p>
          <input type="submit" value="This is a submit button">
        </p>
        <p>
          <button type="reset">
              This a <br><strong>reset button</strong>
          </button>
        </p>
        <p>
          <input type="reset" value="This is a reset button">
        </p>
        <p>
          <button type="button">
              This an <br><strong>anonymous button</strong>
          </button>
        </p>
        <p>
          <input type="button" value="This is an anonymous button">
        </p>

在这里插入图片描述button的文本可以styling

高级表单部件
  • 数字
    属性:min max step
  • 滑块
    属性:min max step
  • 日期时间选择器
    属性:max min
    本地时间:datetime-local
    月:month
    时间:time
    星期:week
  • 拾色器
 <form>
        <p>
          <label for="age">What is your age?</label>
          <input type="number" name="age" id="age" min="1" max="10" step="2">
        </p>
        <p>
          <label for="beans">How many beans can you eat?</label>
          <input type="range" name="beans" id="beans" min="0" max="500" step="10">
          <span class="beancount"></span>
        </p>
        <p>
          <label for="myDate">When are you available this summer?</label>
          <input type="date" name="myDate" min="2013-06-01" max="2013-08-31" id="myDate">
        </p>

        <p>
          <label for="meet">When shall we have the meeting?</label>
          <input type="datetime-local" name="meet" id="meet">
        </p>
        <p>
          <label for="month">What month is your favorite?</label>
          <input type="month" name="month" id="month">
        </p>
        <p>
          <label for="time">Set the time for your wifi fridge</label>
          <input type="time" name="time" id="time">
        </p>
        <p>
            <label for="week">whick week</label>
            <input type="week" name="week" id="week">
        </p>
        <p>
          <label for="color">What is your favourite color?</label>
          <input type="color" name="color" id="color">
        </p>
    </form>

在这里插入图片描述

其他小部件
  • 文件选择器
    accept属性来约束接受的文件类型
    multiple选择多个文件
  • 隐藏内容
    other-examples.html?file=&timestamp=1286705410&pos.x=197&pos.y=101
  • 图像按钮
    other-examples.html?file=&timestamp=1286705410&pos.x=197&pos.y=101
  • 仪表和进度条
    进度条progress
    仪表meter
<form>
        <p>
          <label for="file">Choose an image to upload</label>
          <input type="file" name="file" id="file" accept="image/*" multiple>
        </p>
        <div>
          <input type="hidden" id="timestamp" name="timestamp" value="1286705410">
        </div>
        <p>
          <input type="image" name="pos" alt="" src="map.png">
        </p>
        <p>
          <progress max="100" value="75">75/100</progress>
        </p>
        <p>
          <meter min="0" max="100" value="75" low="33" high="66" optimum="50">75</meter>
        </p>
    </form>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值