Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zurb foundation 如果复选框组中未选中复选框,则显示错误 在同一个复选框组中,如果没有选中复选框,如何显示基础5的ListHTML5表单验证库的错误消息? < p>您必须编写自己的Layer-ValueStor,但非常简单。_Zurb Foundation_Zurb Foundation 5 - Fatal编程技术网

Zurb foundation 如果复选框组中未选中复选框,则显示错误 在同一个复选框组中,如果没有选中复选框,如何显示基础5的ListHTML5表单验证库的错误消息? < p>您必须编写自己的Layer-ValueStor,但非常简单。

Zurb foundation 如果复选框组中未选中复选框,则显示错误 在同一个复选框组中,如果没有选中复选框,如何显示基础5的ListHTML5表单验证库的错误消息? < p>您必须编写自己的Layer-ValueStor,但非常简单。,zurb-foundation,zurb-foundation-5,Zurb Foundation,Zurb Foundation 5,工作示例: JavaScript $(document).foundation({ abide: { validators: { checkbox_limit: function(el, required, parent) { var group = parent.closest('.checkbox-group'); var min = group.attr('data-abide-

工作示例:

JavaScript

$(document).foundation({
    abide: {
        validators: {
            checkbox_limit: function(el, required, parent) {
                var group = parent.closest('.checkbox-group');
                var min = group.attr('data-abide-validator-min');
                var checked = group.find(':checked').length;
                if (checked >= min) {
                    group.find('small.error').hide();
                    return true;
                } else {
                    group.find('small.error').css({
                        display: 'block'
                    });
                    return false;
                }
            }
        }
    }
});
HTML


选择您喜爱的车辆
汽车
火车
自行车
摆渡
飞机
您必须至少检查一辆车。
提交

感谢您提供了一个很好的示例。
<form data-abide>
   <div class="row">
      <div class="small-12 column">
         <h4>Select your favourite vehicles</h4>
      </div>
   </div>
   <div class="row">
      <div class="small-12 columns checkbox-group" data-abide-validator-min="1">
         <label>
            <input type="checkbox" data-abide-validator="checkbox_limit" value="car" />
            car
         </label>
         <label>
            <input type="checkbox" data-abide-validator="checkbox_limit" value="train" />
           train
         </label>
         <label>
            <input type="checkbox" data-abide-validator="checkbox_limit" value="bicycle" />
            bicycle
         </label>
         <label>
            <input type="checkbox" data-abide-validator="checkbox_limit" value="ferry" />
            ferry
         </label>
         <label>
            <input type="checkbox" data-abide-validator="checkbox_limit" value="plane" />
            plane
         </label>
         <small class="error">You have to check at least one vehicle.</small>
      </div>
   </div>
   <div class="row">
      <div class="small-12 columns">
         <button type="submit">Submit</button>
      </div>
   </div>
</form>