使用Javascript配置Parsley,而不是html数据属性 [英] Configure Parsley using Javascript, not html data attributes
问题描述
如何使用javascript配置Parsley,而不是html数据属性?
How do I configure Parsley using javascript, not html data attributes?
文档示例显示如何使用JS配置Parsley表单实例和一些全局字段选项,但我希望能够添加和配置所有字段实例。我不想使用html数据属性。这可能吗?
The documentation examples show how to configure the Parsley form instance and some global field options using JS, but I want to be able to add and configure all field instances that way too. I don't want to use the html data attributes. Is that possible?
我认为这个问题正在引发同样的问题,如何使用ParsleyJS 2. *使用javascript而不是数据属性,但它并非100%清晰。
I think this question is driving at the same problem, How to use ParsleyJS 2.* using javascript and not data attributes, but it's not 100% clear.
推荐答案
@ kim-prince希望这有帮助
@kim-prince Hope this helps
<form id="myForm">
<input id="number" placeholder="Number" />
<input type="submit" />
</form>
<script>
$('#myForm').parsley();
$("#number").parsley().addConstraint('type','number');
$("#number").parsley().addConstraint('minlength',2);
$("#number").parsley().addConstraint('required');
</script>
查看工作代码:
http://codepen.io/ds0001/pen/QwoRVx?editors=101
这篇关于使用Javascript配置Parsley,而不是html数据属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!