目录

自定义控件(Custom Controls)

描述 (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>

输出 (Output)

让我们执行以下步骤,看看上面给出的代码是如何工作的 -

  • 保存上面给出的html代码form_custom_controls.html文件。

  • 在浏览器中打开此HTML文件,输出显示如下。

新页面打开
↑回到顶部↑
WIKI教程 @2018