包括在头:
<script src="jquery-1.11.0.min.js"></script> <script src="fm.validator.jquery.js"></script>
插件激活:
默认初始化时,插件将寻找任何形式包含类验证器,将自身添加到表单的提交事件,然后寻找验证器html5数据属性表明什么以及它如何应该验证表单中的元素。但是你也可以手动验证表单,通过运行验证器。验证功能。这里有一个例子:
if (Validator.validate('#someForm')) { alert('The form is valid, awesome!'); return true; } else { alert('The form is NOT valid!'); }
html5数据属性:
下面是一个示例所需的一个文本框和内容需要3至12个字符。
<form method="post" class="validator"> <input type="text" data-required data-min="3" data-max="12"> </form>
全局选项
全球语言选项,elementErrorClass和语言翻译,可以在全球设置选项。
这里是一个例子。语言设置为丹麦,改变错误的名称类应用于输入元素:
Validator.language = 'da'; Validator.elementErrorClass = 'fejl';
支持验证
属性 | 有效值 | 描述 |
---|---|---|
data-required | no value | If this is set, then the input will require some content |
data-required-if | element id | If set to an id of an element, then it will only be required if said element is checked or has the value of data-required-if-value |
data-required-if-value | element value | If data-required-if is set to an element id, then it will only be required if said element has said value |
data-min=0-9 | 0-9 | The minimum length of the input |
data-max=0-9 | 0-9 | The maximum length of the input |
data-type | email ,url ,number ,digits | email are url are self explanatory, number are the characters 0-9 + - . , , digits are the characters 0-9 only |
data-error-position | before ,after ,before-{tagname} ,after-{tagname} | By default the error messages will appear before the input element in the DOM, but you can also set it to appear after . If neede then you can also set it t be before or after the closest parent matching the tagname specified after the dash - |
密码输入:
Attribute | Valid values | Description |
---|---|---|
data-required | no value | If this is set, then the input will require some content |
data-required-if | element id | If set to an id of an element, then it will only validate if said element is checked or has the value of data-required-if-value |
data-required-if-value | element value | If data-required-if is set to an element id, then it will only validate if said element has said value |
data-min=0-9 | 0-9 | The minimum length of the input |
data-max=0-9 | 0-9 | The maximum length of the input |
data-match | element id | If set to an id of another input element, it will match the contents against that element |
data-error-position | before ,after ,before-{tagname} ,after-{tagname} | By default the error messages will appear before the input element in the DOM, but you can also set it to appear after . If neede then you can also set it t be before or after the closest parent matching the tagname specified after th |
$(this).attr('data-required-if') != undefined && $(this).val() == '' && (($(this).attr('data-required-if-value') == undefined && $('#' + $(this).attr('data-required-if')).is(':checked')) || ($(this).attr('data-required-if-value') != undefined && $('#' + $(this).attr('data-required-if')).val() == $(this).attr('data-required-if-value')))
代码里面这个判断是什么意思
required: 'Dette felt skal udfyldes',min: 'Dette felt skal v?re mindst {characters} tegn',max: 'Dette felt skal v?re h?jst {characters} tegn',email: 'Denne email er ugyldig',url: 'Denne webside er ugyldigt',number: 'Kun tal',digits: 'Kun tal'
这些可以自动换成中文吗 语言输入::中文应该输入什么
回复怎么把提示换成中文
个人感觉不错,谢谢分享