zoukankan      html  css  js  c++  java
  • 1.9、html表单

     

    表单用于搜集不同类型的用户输入,表单由不同类型的标签组成,实现一个特定功能的表单区域(比如:注册),首先应该用<form>标签来定义表单区域整体,在此标签中再使用不同的表单控件来实现不同类型的信息输入,具体实现及注释可参照以下伪代码:

    <!-- form定义一个表单区域,action属性定义表单数据提交的地址,
    method属性定义提交的方式。   -->
    <form action="http://www..." method="get">
    
    <!-- label标签定义表单控件的文字标注,input类型为text定义了
    一个单行文本输入框  -->
    <p>
    <label>姓名:</label><input type="text" name="username" />
    </p>
    
    <!-- input类型为password定义了一个密码输入框  -->
    <p>
    <label>密码:</label><input type="password" name="password" />
    </p>
    
    <!-- input类型为radio定义了单选框  -->
    <p>
    <label>性别:</label>
    <input type="radio" name="gender" value="0" /><input type="radio" name="gender" value="1" /></p>
    
    <!-- input类型为checkbox定义了单选框  -->
    <p>
    <label>爱好:</label>
    <input type="checkbox" name="like" value="sing" /> 唱歌
    <input type="checkbox" name="like" value="run" /> 跑步
    <input type="checkbox" name="like" value="swiming" /> 游泳
    </p>
    
    <!-- input类型为file定义上传照片或文件等资源  -->
    <p>
    <label>照片:</label>
    <input type="file" name="person_pic">
    </p>
    
    <!-- textarea定义多行文本输入  -->
    <p>
    <label>个人描述:</label>
    <textarea name="about"></textarea>
    </p>
    
    <!-- select定义下拉列表选择  -->
    <p>
    <label>籍贯:</label>
    <select name="site">
        <option value="0">北京</option>
        <option value="1">上海</option>
        <option value="2">广州</option>
        <option value="3">深圳</option>
    </select>
    </p>
    
    <!-- input类型为submit定义提交按钮  
         还可以用图片控件代替submit按钮提交,一般会导致提交两次,不建议使用。如:
         <input type="image" src="xxx.gif">
    -->
    <p>
    <input type="submit" name="" value="提交">
    
    <!-- input类型为reset定义重置按钮  -->
    <input type="reset" name="" value="重置">
    </p>
    
    </form>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>表单</title>
    </head>
    <body>
    <form action="http://www.baidu.com" method="get">
        <div>
    <!--        设置for 属性, 点击文字激活输入框-->
            <label for="usernm"> 用户名:</label>
            <input type="text" name="username" id="usernm">
        </div>
        <br />
        <div>
            <label>密码:
                <input type="password" name="passwd">
            </label>
        </div>
        <br />
        <div>
            <label>文件:
                <input type="file" name="uploadfile">
            </label>
        </div>
        <br />
        <div>
            <label>性别:</label>
            <!--        设置for 属性, 点击文字激活输入框-->
            <input type="radio" name="gender" id="male"> <label for="male"></label>
            <input type="radio" name="gender" id="female"> <label for="female"></label>
    
        </div>
        <br />
        <div>
            <label>爱好:</label>
    <!--        用label标签把input标签包起来,也可以实现激活效果-->
            <label>
                <input type="checkbox" name="hobby"></label>
            <label>
                <input type="checkbox" name="hobby"></label>
            <label>
                <input type="checkbox" name="hobby"></label>
    
        </div>
        <br />
        <div>
            <label>简介:
                <textarea name="jianjie"></textarea>
            </label>
        </div>
        <br />
        <div>
            <label>籍贯:
                <select name="jiguan">
                    <option>北京</option>
                    <option>上海</option>
                    <option>广州</option>
                    <option>深圳</option>
                </select>
            </label>
        </div>
        <input type="hidden" name="hid" value="10000">  <!-- 隐藏不会在页面显示: 可以临时存储数据 -->
        <input type="submit" name="submitttttt" value="提交">
        <input type="reset" name="resettt" value="重置">
        <input type="image" name="another_submit" src="../images/24.png" alt="提交" >    <!-- 也可以提交表单: 但存在缺陷,有时会提交两次 -->
    
    
    </form>
    </body>
    </html>
  • 相关阅读:
    EF之POCO应用系列4——延迟加载
    四色原型札记(一)
    HTTP1.1 > HTTP2.0
    【ArangoDB踩坑】字符串查询要加引号
    利用线程池实现多客户端和单服务器端Socket通讯(二):异步编程模型实现
    题目:若干个不重复数,打乱顺序输出
    wtf js(三) number的类型不是number
    wtf js(二)
    算法:给定两个已从小到大排好序的整型数组arrA和arrB,将两个数组合并成arrC,使得arrC也要按从小到大的顺序排好序
    利用线程池实现多客户端和单服务器端Socket通讯(一):同步方式
  • 原文地址:https://www.cnblogs.com/LiuYanYGZ/p/12254546.html
Copyright © 2011-2022 走看看