当前位置:   article > 正文

HTML5入门 之下拉菜单_html5 下拉框

html5 下拉框

前言

接着上面的操作,添加下拉菜单

参考视频:
1.黑马程序员5天软件测试从入门到精通_软件测试基础教程

1.写入代码

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <!-- 所有要填写的内容都要放在form标签中
            action 代表数据给哪个个后台程序
             method 代表输入数据的方法 1、post(加密) 2、get(不加密)
         -->
        <form action="" method="POST">
            <!--  input 代表输入框标签(单标签),
                  type 类型决定这个输入的类型,
                  name 属性代表这个输入框的名字,
                   id 打包输入框的id 编号
                  value 代表默认输入框的值 -->
            <!-- nicheng:<input type="text" name="hha" id="hhee" value="hahaha"/> -->
            昵称: <input type="text" name="hha" id="hhee" placeholder="hahha"/> 
            <!-- placeholder 属于ie低版本不兼容,但是不会造成页面的混乱,认为此属性没问题 -->
            <br />
            <!-- input 的type 类型是password 代表密码筐,用户输入的文字会加密 -->
            密码: <input type="password" />   <br />
            性别: <input type="radio" name="xb"  id="nan" checked=checked /><label for="nan"></label> 
            <input type="radio" name="xb" id="nv"/> <label for="nv"></label> 
            <input type="radio" name="xb" id="baomi"/> <label for="baomi"> 保密</label>  <br />
            地址: 
            <select name="" >
                <option >美国</option>
                <option selected="selected">中国 </option>
                <option >俄罗斯 </option>
                <option >韩国</option>
            </select>
            <select name="" >
                <optgroup label="北京">
                    <option >海淀</option>
                    <option >朝阳 </option>
                    <option >顺义</option>
                    <option >东城</option>
                </optgroup>
                <optgroup label="上海">
                    <option >黄浦</option>
                    <option >宝山</option>
                    <option> 嘉定</option>
                    <option selected="selected" >松江</option>
                </optgroup>
            </select>
        </form>
    </body>
</html>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

2.页面展示

在这里插入图片描述

总结

select 和 option 的组合

  • 如果想设置多组下拉菜单,需要添加一个optgroup 标签,并设置为label 属性作为提示文字
  • 如果想设置默认选中状态,需要给对应的option 添加selected 属性,
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/254008
推荐阅读
相关标签
  

闽ICP备14008679号