Abide Demo

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

描述 (Description)

Abide在HTML5表单验证库中使用本机API,使用必需的属性和模式。

例子 (Example)

以下示例演示了在Foundation中使用abide插件 -

<!DOCTYPE html>
<html>
   <head>
      <title>Foundation Template</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/css/foundation.css">
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/foundation.min.js"></script>
      <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.js"></script>
   </head>
   <body>
      <h2>Example of Abide</h2>
      <form data-abide novalidate>
         <div data-abide-error class = "alert callout" style = "display: none;">
            <p><i class = "fi-alert"></i> There are some errors in your form.</p>
         </div>
         <div class = "row">
            <div class = "small-12 columns">
               <label>Name
                  <input type = "text" placeholder = "Name" required pattern = "[a-zA-Z]+">
                  <span class = "form-error">Fill the Correct box</span>
               </label>
               <label>Email
                  <input type = "text" placeholder = "abd@email.com" pattern = "email">
               </label>
            </div>
         </div>
         <div class = "row">
            <div class = "medium-4 columns">
               <fieldset>
                  <label>Gender</label>
                  <input type = "radio" name = "pockets" value = "Male">
                  <label>Male</label>
                  <input type = "radio" name = "pockets" value = "Female">
                  <label>Female</label>
                  <input type = "radio" name = "pockets" value = "Other">
                  <label>Other</label>
               </fieldset>
               <label>Input Label
                  <select id = "select" required>
                     <option value = ""></option>
                     <option value = "volvo">Volvo</option>
                     <option value = "saab">Saab</option>
                     <option value = "mercedes">Mercedes</option>
                     <option value = "audi">Audi</option>
                  </select>
               </label>
            </div>
         </div>
         <div class = "row">
            <fieldset class = "large-6 columns">
               <button class = "button" type = "submit" value = "Submit">Submit</button>
               <button class = "button" type = "reset" value = "Reset">Reset</button>
            </fieldset>
         </div>
      </form>
      <script>
         $(document).ready(function() {
            $(document).foundation();
         })
      </script>
   </body>
</html>

Details of the code are as follows -

  • 最初编写以下代码用于创建表单。 《form data-abide novalidate》是最初编写的元素。

<form data-abide novalidate>
   <div data-abide-error class = "alert callout" style = "display: none;">
     <p><i class = "fi-alert"></i> There are some errors in your form.</p>
   </div>
   <div class = "row">
      <div class = "small-12 columns">
         <label>Name
            <input type = "text" placeholder = "Name" required pattern = "[a-zA-Z]+">
            <span class = "form-error">Fill the Correct box</span>
         </label>
      </div>
   </div>
</form>
  • 在表单中,我们已经包含了在填写表单时要为特定字段显示的错误状态。 data-abide-error class = "alert callout"元素给出完整表单的错误状态。

  • 当输入的输入错误时, form-error类显示特定字段的错误。

<form data-abide novalidate>
   <div data-abide-error class = "alert callout" style = "display: none;">
       <p><i class = "fi-alert"></i> There are some errors in your form.</p>
   </div>
   <div class = "row">
      <div class = "small-12 columns">
         <label>Name
            <input type = "text" placeholder = "Name" required pattern = "[a-zA-Z]+">
            <span class = "form-error">Fill the Correct box</span>
         </label>
      </div>
   </div>
</form>