• 技术文章 >web前端 >H5教程

    html5+css3 |表单的应用

    黄舟黄舟2017-02-07 13:20:46原创966
    1.创建表单的基本语法格式如下:

    <from action=”url 地址”method=”提交方式”name=”表单名称”>
         各种表单控件
    </form>

    如下例子:

    P212-213
    <!doctype html>
    <html>
    <head>
    <meta charset=”utf-8”>
    <title>创建表单</title>
    </head>
    <body>
    <from action=”http://www.mysite.cn/index.asp”method=”post” id=”formBox”autocomplete=”on”>
      用户名:
      <input type=”text”id=”autofirst”name=”autofirst”/><br/><br/>
      账号:
      <input type=”text”name=”zhanghao”/>
      密码:
      <input type=”password”name=”mima”/>
      <input type=”submit”value=”提交”/>
    </form>
    </body>
    </html>

    2.input元素的type属性

    (1)单行文本输入框<input type=”text”/>

    用户名:name;账号:value;证件号:maxlength

    (2)密码输入框<input type=”password”/>

    (3)单选按钮<input type=”radio”/>

    (4)复选框<input type=”chexkbox”/>

    (5)普通按钮<input type=”button”/>

    (6)提交按钮<input type=”submit”/>

    (7)重置按钮<input type=”reset”/>

    (8)图像形式的提交按钮<input type=”image”/>

    (9)隐藏域<input type=”hidden”/>

    (10)文件域<input type=”file”/>

    (11)email类型<input type=”email”/>

    (12)url类型<input type=”url”/>

    (13)tel类型<input type=”tel”/>

    (14)search类型<input type=”search”/>

    (15)color类型<input type=”color”/>

    (16)number类型<input type=”number”/>

    <input type=”number”name=”number1”value=”1”min=”1”max=”20”step=”4”/><br/>

    (17)range类型<input type=”range”/>

    (18)Date pickers类型<input type=”date,month,week...”/>

    <form action=”#”method=”get”>
      <input type=”date”/>;
      <input type=”month”/>;
      <input type=”week”/>;
      <input type=”time”/>;
      <input type=”datetime”>
      <input type=”datetime-local”/>
      <input type=”submit”value=”提交”/>
    </form>

    3.其它元素

    (1)list属性

    <form action=”#”method=”get”>
    请输入网址:<input type=”url”list=”url_list”name=”weburl”/>
    <datalist id=”url_list”>
      <option label=”新浪”value=”http://www.sina.com.cn”></option>
      <option label=”搜狐”value=”http://www.sohu.com.cn”></option>
      <option label=”传智”value=”http://www.itcast.cn/”></option>
    </datalist>


    (2)multiple属性

    <form action=”#”method=”get”>
    电子邮箱:<input type=”email”name=”myemail”multiple=”true”/>
    上传照片:<input type=”file”name=”selfile”multiple=”true”/><br/><br/>
    <input type=”submit”value=”提交“/>
    </form>


    (3)placeholder属性

    <form actiom=”#”method=”get”>
    请输入邮政编码:<input type=”text”name=”code”pattern=”[0-9]{6}”placeholder=”请输入6位数的邮政编码”/>
    <input type=”submit”value=”提交”/>
    </form>


    (4)textarea元素

    <textarea cols=”每行中的字符数”rows=”显示的行数“>
     文本内容
    </textarea>

    例子:

    <form action=”#”method=”post”>
    评论:<br/>
         <textarea cols=”60”rows=”8”>
    评论的时候,请遵纪守法并注意语言文明。
         </textarea><br/>
         <input type=”submit”value=”提交”/>
    </form>

    (5)select元素

    <select>  //<optgroup>
      <option>1</option>
      <option>2</option>
      <option>3</option>
    </select>


    (6)datalist元素

    <form action=”#”method=”post”>
    请输入用户名:<input type=”text”list=”namelist”/>
    <datalist id=”namelist”>
      <option>admin</option>
      <option>lucy</option>
    </datalist>
    <input type=”submit”value=”提交”/>
    </form>


    (7)keygen元素

    <form action=”#”method=”get”>
    请输入用户名:<input type=”text”name=”user_name”/><br/>
    请选择加密强度:<keygen name=”security”/><br/>
    <input type=”submit”value=”提交”/>
    </form>

    表单样式

    <!doctype html>
    <html><head>
    <meta charset="utf-8">
    <title>CSS控制表单样式</title>
     
    <style type="text/css">
    body{ font-size:12px; font-family:"宋体";}
    body,form,input,p{ padding:0; margin:0; border:0;}
    form{
                  width:320px;
                  height:150px;
                  padding-top:20px;
                  margin:50px auto;
                  background:#f5f8fd;
                  border-radius:20px;
                  border:3px solid #4faccb;
    }
    p{
                  margin-top:15px;
                  text-align:center;
    }
    p span{
                  width:40px;
                  display:inline-block;
                  text-align:right;
    }
    .num,.pass{
                  width:152px;
                  height:18px;
                  border:1px solid #38a1bf;
        padding:2px 2px 2px 22px;
    }
    .num{
                   background:url(images/1.jpg) no-repeat 5px center #FFF;
                   color:#999;
    }
    .pass{
                   background:url(images/2.jpg) no-repeat 5px center #FFF;
    }
    .btn01,.btn02{
                  width:60px;
                  height:25px;
                  border-radius:3px;
                  border:1px solid #6b5d50;
                  margin-left:30px;
    }
    .btn01{ background:#3bb7ea;}
    .btn02{ background:#fb8c16;}
    </style>
     
    <link rel="stylesheet" href="Untitled-1.css" type="text/css">
    </head>
    <body>
    <form action="#" method="post">              
         <p>
        登录:<input type="tel" name="telphone" pattern="^\d{11}$" required/>
         </p>
          <p>
        密码:<input type="tel" name="telphone" pattern="^\d{11}$" required/>
        </p>
        <p>
            <input type="button" class="btn01" value="登录"/>
            <input type="button" class="btn02" value="注册"/>
       </p>
    </form>
    </body>
    </html>

    以上就是html5+css3 |表单的应用的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:html5,css3,表单
    上一篇:HTML5:使用Canvas实时处理Video 下一篇:HTML5教程-Web存储
    Web大前端开发直播班

    相关文章推荐

    • 小强的HTML5移动开发之路(3)——HTML5与HTML4比较• HTML5边玩边学(二)-基础绘图• phonegap使用方法介绍(八)操作数据库• html5配合css3实现带提示文字的输入框(摆脱js)_html5教程技巧• HTML5 b和i标记将被赋予真正的语义_html5教程技巧

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网