• JavaScript获取select下拉框中的第一个值


    JavaScript获取select下拉框中的第一个值


    1、说明

          获取select下拉框中的第一个值


    2、实现源代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>JavaScript获取select下拉框中的第一个值</title>
    <script type="text/javascript">
         /**
    	  * JavaScript获取select下拉框中的第一个值
    	  */
         function getFirstValOfSelect()
    	 {
    		 //获取select中的ID
    		 var selectId = document.getElementById("select_option");
    		 //获取select下拉框中第一个值
    		 var selectValue = selectId.options[0].value;
    		 //获取select下拉框中第一个文本值
    		 var selectText = selectId.options[0].text;
    		 //打印select下拉框中第一个值和文本值
    		 alert("值:" + selectValue + "
    " + "文本值:" + selectText);
    	 }
    </script>
    </head>
    
    <body>
       <div id="div_select">
           <select id="select_option">
                <option value="0">桃树</option>
                <option value="1">梨树</option>
                <option value="2">樟树</option>
                <option value="3">枫树</option>
                <option value="4">松树</option>
                <option value="5">梧桐树</option>
                <option value="6">槐树</option>
           </select>
       </div>
       <input type="button" value="JavaScript获取select下拉框中的第一个值" onclick="getFirstValOfSelect()"/>
    </body>
    </html>
    

    3、实现结果

    (1)选中第一项



    (2)选中第二项


  • 相关阅读:
    J2ME 游戏开发之GameCanvas的使用
    J2ME游戏开发之字符串的绘制
    JS数组操作
    什么是LBS?地理位置服务
    js中的this怎么理解
    相机参数
    boost 移植到ARM EP9315
    armlinuxgcc 安装和配置
    小算法 : 水仙花数
    C语言标准库 文件操作
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7043611.html
Copyright © 2020-2023  润新知