zoukankan      html  css  js  c++  java
  • 获取下拉菜单中具有SELECTED属性元素的序号和值的方法

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4     <meta charset="utf-8">
     5     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     6     <title></title>
     7     <link rel="stylesheet" href="">
     8 </head>
     9 <body>
    10     <form action="">
    11         <p>
    12             <label for="backgroundColor">选择背景色:</label>
    13             <select id="backgroundColor">
    14                 <option value="white" selected="selected">White</option>
    15                 <option value="black">Black</option>
    16             </select>
    17         </p>
    26 
    27         <p>
    28             <input type="button" id="previewButton" value="Preview">
    29         </p>
    30     </form>
    31 
    32 <script>
    33     var bgColor = document.getElementById('backgroundColor');
    34     var preview = document.getElementById('previewButton');
    35 
    36     var index = bgColor.selectedIndex;
    37     var value = bgColor[index].value;
    38 
    39     preview.addEventListener('click',function(){
    40         console.log(index);    //0
    41         console.log(value);    //white
    42     })
    43     
    44 </script>
    45 </body>
    46 </html>
  • 相关阅读:
    IntentService源码分析
    startService过程源码分析
    洛谷P3300 城市规划
    agc033
    洛谷P3306 随机数生成器
    洛谷P3299 保护出题人
    洛谷P3298 泉
    洛谷P3296 刺客信条
    树hash
    我们都爱膜您退火!
  • 原文地址:https://www.cnblogs.com/xiadengqi/p/11224318.html
Copyright © 2011-2022 走看看