自定义控件(Custom Controls)

优质
小牛编辑
131浏览
2023-12-01

描述 (Description)

日期选择器,开关或滑块等自定义控件需要一些注意才能访问它。 使用标签帮助文本或自定义输入,需要添加aria-labelledbyaria-describedby属性。 这将有助于屏幕阅读器描述控件。

例子 (Example)

以下示例演示了在Foundation中使用custom controls

<html>
   <head>
      <title>Form Custom Controls</title>
      <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/css/foundation.css">
   </head>
   <body>
      <form>
         <label id = "rateLabel">Rate Yourself</label>
         <div class = "slider" aria-labelledby = "rateLabel" aria-describedby = "rateHelpText" 
            data-slider data-initial-start = '80' data-end = '100'>
            <span class = "slider-handle" data-slider-handle role = "slider" tabindex = "1"></span>
            <span class = "slider-fill" data-slider-fill></span>
            <input type = "hidden">
         </div>
         <p id = "rateHelpText">how good are you at problem solving?</p>
      </form>
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/vendor/jquery.min.js"></script>
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/foundation.min.js"></script>
      <script>
         $(document).ready(function() {
            $(document).foundation();
         })
      </script>
   </body>
</html>