XHTML表单

表单——输入控件

1)文本框:使用input元素,设置该元素的type属性为text;size(控制文本的长度)、maxlength(用户能够输入的最大字符数)

     例:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>创建表单示例--文本框</title>
</head>
<body>
    <form id="myForm" name="myFrom" action="#" method="post">
        <p>姓<input type="text" id="firstname" size="30" maxlength="25"/></p>
        <p>名<input type="text" id="lastname"size="30" maxlength="25"/></p>
    </form>
</body>
</html>
2)口令输入框:

     

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>创建表单示例--密码输入框</title>
</head>
<body>
   <form id="myForm" name="myForm" action="#" method="post">
       <p>姓<input type="text" id="firstname" size="30" maxlength="25"></p>
       <p>名<input type="text" id="lastname" size="30" maxlength="25"></p>
       <p>口令<input type="password" id="password" size="30" maxlength="25"></p>
   </form>
</body>
</html>
3)复选框和单选框:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html"
<head>
    <meta charset="UTF-8">
    <title>创建表单示例--密码字段</title>
</head>
<body>
   <form id="myForm" name="myForm" action="#" method="post">
       <p>请选择你想要去旅游的城市</p>
       <p>
           <input type="checkbox" name="city" id="sh" value="shanghai" checked="checked">上海</input><br/>
           <input type="checkbox" name="city" id="cd" value="成都">成都</input><br/>
           <input type="checkbox" name="city" id="xa" value="西安">西安</input><br/>
       </p>
       <p>选择你的性别</p>
       <p>
           <input type="radio" name="gender" id="male" value="male">男</input><br/>
           <input type="radio" name="gender" id="female" value="female">女</input><br/>
       </p>
   </form>
</body>
</html>
4)隐藏字段:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>创建表单示例--隐藏字段</title>
</head>
<body>
    <form id="myForm" name="myForm" action="#" method="post">
        <input type="hidden" id="e-mail" value="me@mysite.com">
        <p>姓<input type="text" id="firstname" size="30" maxlength="25"></p>
        <p>名<input type="text" id="lastname" size="30" maxlength="25"></p>
        <p>口令<input type="password" id="password" size="30" maxlength="25"></p>
    </form>
</body>
</html>
5)文件上传控件:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>创建表单示例--文件上传控件</title>
</head>
<body>
    <form id="myForm" action="#" method="post" enctype="form/multipart">
        <p>请以Word文档格式提供您的简历</p>
        <input type="file" id="resume">
    </form>
</body>
</html>
6)下拉列表:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>创建表单示例--文件上传控件</title>
</head>
<body>
    <form id="myForm" action="#" method="post" enctype="form/multipart">
        <p>请以Word文档格式提供您的简历</p>
        <input type="file" id="resume">
    </form>
</body>
</html>
7)多行文本框:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>创建表单示例--多行文本框</title>
</head>
<body>
   <form id="myForm" name="myForm" action="#" method="post">
       <textarea rows="10" cols="30" id="comment">请在此输入文本</textarea>
   </form>
</body>
</html>
8)提交和重置按钮

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>创建表单示例--提交和重置按钮</title>
</head>
<body>
    <form id="myForm" name="myForm" action="#" method="post">
        <p>您最喜欢的餐饮风格是?</p>
        <select id="food" multiple="multiple" size="4">
            <option value="sichuan">川菜</option>
            <option value="guangdong">粤菜</option>
            <option value="beifang">北方菜</option>
            <option value="shanghai">上海菜</option>
            <option value="west" selected="selected">西餐</option>
            <option value="tailand">泰国菜</option>
        </select>
        <p>
            <input type="submit" value="发送">
            <input type="reset" value="清除">
        </p>
    </form>
</body>
</html>

9)命令按钮:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>创建表单示例--普通命令按钮</title>
</head>
<body>
   <form id="myForm" name="myForm" action="#" method="post">
       <p>您最喜欢的餐饮风格是?</p>
       <select id="food" multiple="multiple" size="4">
           <option value="sichuan">川菜</option>
           <option value="guangdong">粤菜</option>
           <option value="beifang">北方菜</option>
           <option value="shanghai">上海菜</option>
           <option value="west" selected="selected">西餐</option>
           <option value="tailand">泰国菜</option>
       </select>
       <p>
           <input type="button" value="增加">
           <input type="button" value="删除">
       </p>
   </form>
</body>
</html>
10)label元素:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <p>
        <label for="Firstname">Firstname:</label>
        <input type="text" id="Firstname" value="" size="30">
    </p>
</body>
</html>
11)Tab次序和键盘快捷键:
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <label for="FirstName"><u>F</u>irstName:</label>
    <input type="text" id="FirstName" value="" size="30" tabindex="3" accesskey="F">
</body>
</html>
12)防止改变字段内容:
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>readonly和disabled属性示例</title>
</head>
<body>
    <form id="myForm" action="#" method="post">
        <p>
            <label for="oID">订单编号:</label>
            <input type="text" id="oID" size="12" value="X1248" readonly="readonly">
        </p>
        <p>
            <label for="price">订单总价:</label>
            <input type="text" id="price" size="12" value="" disabled="disabled">
        </p>
    </form>
</body>
</html>
13)fieldset和legend元素:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>fieldset和legend元素示例</title>
</head>
<body>
    <form id="myForm" action="#" method="post">
        <fieldset>
            <p>
                <legend>性别</legend>
                <input type="radio" id="gender" name="gender" value="male">男</input><br/>
                <input type="radio" id="gnder" name="gender" value="female">女</input>
            </p>
        </fieldset>
    </form>
</body>
</html>











  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值