我从Parsley 2.0.6升级到了2.2.0,现在我在控制台中收到这个警告:Parsley's pubsub module is deprecated; use the 'on' and 'off' methods on parsley instances or window.Parsley。一切仍然有效,包括由香菜事件侦听器触发的函数,(我相信)在其中找到了这个错误的根源。但我得到了警告。每当我删除警告时,函数就不会运行。
我已经将$.listen('parsley:field:validated')更改为jQuery .on()的每种组合。我还将香菜事件更新为‘`field:validated’。无论我做什么,我的函数都无法运行。这里有一大段原始的相关代码。以下是可以工作的代码,但会在控制台中显示警告:
// check forms for data-parsley-validate attribute. If exests, then extend the config
// with the trigger:'change' option.
$('form, .form').each(function() {
var $form = $(this);
if($form.is('[data-parsley-validate]')) {
ParsleyConfig = $.extend(ParsleyConfig || {}, {
trigger: 'change'
});
}
$form.parsley();
});
$(function () {
// Validation listener for ajdusting height of certain other components/widgets
$.listen('parsley:form:validated', $('[data-modal]'), function () {
if (typeof modalHeightSetter == 'function') { modalHeightSetter(); }
});
// Validation listener for add/removal of .error class from .field-icon's
$.listen('parsley:field:validated', $('[data-field-icon]'), function() {
var $fieldIcons = $(this);
$fieldIcons.each(function() {
var $this = $(this);
if($this.is('.error')) {
$this.prev('.field-icon').addClass('error');
} else if(! $this.is('.error')) {
$this.prev('.field-icon').removeClass('error');
}
});
});
});我按照我认为@Mark-Andre所说的重写了有问题的js,但得到了相同的结果,即销毁警告消失了,但函数没有运行。
// check forms for data-parsley-validate attribute. If exests, then extend the config
// with the trigger:'change' option.
$('form, .form').each(function() {
var $form = $(this);
if($form.is('[data-parsley-validate]')) {
ParsleyConfig = $.extend(ParsleyConfig || {}, {
trigger: 'change'
});
}
$form.parsley();
// Validation listener for ajdusting height of certain other components/widgets
$form.parsley().on('form:validated', $('[data-modal]'), function () {
if (typeof modalHeightSetter == 'function') { modalHeightSetter(); }
});
// Validation listener for add/removal of .error class from .field-icon's
$form.parsley().on('field:validated', $('[data-field-icon]'), function() {
var $fieldIcons = $(this);
$fieldIcons.each(function() {
var $this = $(this);
if($this.is('.error')) {
$this.prev('.field-icon').addClass('error');
} else if(! $this.is('.error')) {
$this.prev('.field-icon').removeClass('error');
}
});
});
});发布于 2015-12-11 23:54:03
检查the doc...on和off方法不是jQuery的,而是Parsley的...
https://stackoverflow.com/questions/34225163
复制相似问题