j查询验证插件更新后的错误"jquery.format is not a function"



多年来,我一直是jQuery.validate,成功地使用了1.9.0版本
现在,使用版本1.19.2,我得到了"jquery.format不是一个函数
在我的头部:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/additional-methods.min.js" ></script>    

html表单输入

<div class="divTableCell L3"><input name="email" type="text" class="required" id="email" /></div>

底部:

<script>
formVerif();
</script>

这是所使用功能的一部分:

function formVerif(){   
$(document).ready(function(){
$("#formulario").validate({
errorClass: 'rojo' ,
messages: {
nombre: {
required: "<br />Falta ingresar un nombre.",
minlength: jQuery.format("<br />Ingresa al menos {0} caracteres"),
maxlength: jQuery.format("<br />Ingresa como máximo {0} caracteres"),
alphanumeric: "<br />Ingresa solo letras y espacios"
},
apellido: {
...
...

如果我回到V 1.9.0,则不会显示错误:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="JS/jquery.validate.min.js"></script>
<script src="JS/additional-methods.min.js"></script>

您的代码。。。

minlength: jQuery.format("<br />Ingresa al menos {0} caracteres"),

没有jQuery.format这样的东西,所以只需删除并使用它。。。

minlength: "<br />Ingresa al menos {0} caracteres",

它仍然有效。。。

演示:jsfiddle.net/w09fqj3n/

查看文档,jQuery.format应该是jQuery.validator.format,但它显然是可选的。


此外,将DOM就绪事件处理程序放在页面底部调用的函数中是没有意义的。。。

function formVerif(){   
$(document).ready(function(){ ....

就绪事件处理程序的主要目的是";指定要在DOM完全加载时执行的函数">从页面底部的函数调用它会使其使用变得毫无意义。如果您希望将加载脚本推迟到最后,只需将就绪处理程序放在底部即可。

jQuery.validator.addMethod("extension", function(value, element, param) {
param = typeof param === "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
},  jQuery.format("Please enter a value with a valid extension."));

删除jQuery.format()

最新更新