我正在尝试用parsley.js验证单选按钮。下面是我尝试使用的代码
<p id="registration_field_custom2" class="onefield registration_field_custom2">
<span class="doyou">
<span class="text">etc etc etc etc ?</span>
<input type="radio" name="custom2" value="Yes" id="custom2_yes"
data-required="true"
data-error-container="#submitDetails .error6"
data-error-message ="Please chose either yes or no"
/>
<label for="custom2_yes">Yes</label>
<input type="radio" name="custom2" value="No" id="custom2_no"
/>
<label for="custom2_no">No</label>
</span>
</p>然而,无论我选择是还是否,它仍然在寻找两者都需要的数据。我只想让用户能够选择是或否…我怎么用parsley.js做到这一点呢?
发布于 2013-07-13 17:19:36
我认为对于无线输入和复选框是特殊情况,而不是使用data-required,你应该使用data-mincheck来确保至少有一个选项被选中。
发布于 2013-10-23 17:23:31
要验证香菜中的单选按钮,只需使用- data-required="true“即可。你不需要使用data-mincheck for单选按钮。由于单选按钮具有相同的名称,香菜会自动识别出它们在同一组中。在香菜文档中有一个很好的例子:http://parsleyjs.org/doc/index.html
示例:
<input id="radio-required" class="parsley-validated" type="radio" data-required="true" value="foo" name="radiorequired">
<input id="radio-required2" type="radio" value="bar" name="radiorequired">发布于 2017-09-18 20:41:32
data-mincheck适用于复选框验证。
data-parsley-required="true“用于选项验证
http://parsleyjs.org/doc/examples/simple.html
https://stackoverflow.com/questions/17378981
复制相似问题