【问题标题】:Applying AddMethod() to validation function将 AddMethod() 应用于验证函数
【发布时间】:2009-08-14 14:11:50
【问题描述】:

我是 jquery 的新手,我正在尝试验证一组复选框 [] 使用validation plugin。在网上搜索后,我遇到了 这个 AddMethod( ) 似乎解决了复选框的问题,但我 找不到任何解释如何应用新方法名称的代码 到 validate()。

这是我想要实现的代码

<script type="text/javascript">

jQuery.validator.addMethod('minchecked',function(value, element) {
          return $(element).filter(':checked').length >= 1;
}, 'please make a selection');

$(document).ready(function(){
   $("#onlinesurvey").validate({
      rules: {
         <!== do not know how apply the new method if it does go here ==>
      }
    });
});
</script>

<html>
<body>
<form id="onlinesurvey">
<fieldset id="stageone">
<label for="q1a"><input type="checkbox" name="q1[]" id="q1a" value="Blue Square Casino" />Blue Square Casino</label>
<label for="q1b"><input type="checkbox" name="q1[]" id="q1b" value="Paddy Power" />Paddy Power</label>
<label for="q1c"><input type="checkbox" name="q1[]" id="q1c" value="Sky Vegas" />Sky Vegas</label>
<label for="q1d"><input type="checkbox" name="q1[]" id="q1d" value="Virgin Casino" />Virgin Casino</label>
<label for="q1e"><input type="checkbox" name="q1[]" id="q1e" value="Other(s)" />Other(s)</label>
<label for="q1[]" class="error">Please make a selection</label>
</div>  
<input type="button" value="next" class="next" />
</fieldset>
</form>
</body>
</html>

【问题讨论】:

  • 您应该在解决方案中输入答案并接受它。

标签: jquery jquery-plugins jquery-validate


【解决方案1】:
$("#onlinesurvey").validate({
  rules: {
     minchecked: true
  }
});

【讨论】:

  • 我应用了那段代码,但它仍然不起作用 - 我的困惑是 addMethod "minchecked" 应用于该表单的每个复选框旅馆
猜你喜欢
  • 1970-01-01
  • 2011-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-20
  • 2011-03-12
相关资源
最近更新 更多