Foundation - 自定義控制元件



說明

日期選取器、開關或滑塊等自定義控制元件需要一些注意才能訪問它。帶有標籤的幫助文字或自定義輸入,需要向其中新增_aria-labelledby_和_aria-describedby_屬性。這將幫助螢幕閱讀器描述控制元件。

示例

以下示例演示了在Foundation中使用_自定義控制元件_。

<html>
   <head>
      <title>Form Custom Controls</title>
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/foundation-sites@6.5.1/dist/css/foundation.min.css" crossorigin="anonymous">

      <!-- Compressed JavaScript -->
      <script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/vendor/jquery.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/foundation-sites@6.5.1/dist/js/foundation.min.js" crossorigin="anonymous"></script>

   </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>
         $(document).ready(function() {
            $(document).foundation();
         })
      </script>
   </body>
</html>

輸出

讓我們執行以下步驟,瞭解上面給出的程式碼是如何工作的 -

  • 儲存上面給出的html程式碼**form_custom_controls.html**檔案。

  • 在瀏覽器中開啟此HTML檔案,顯示的輸出如下。

foundation_forms.htm
廣告