Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery删除欧芹不';好像不行_Javascript_Jquery_Parsley.js - Fatal编程技术网

Javascript 使用jquery删除欧芹不';好像不行

Javascript 使用jquery删除欧芹不';好像不行,javascript,jquery,parsley.js,Javascript,Jquery,Parsley.js,我有一项任务要求我使用欧芹选择性地验证输入,然后在输入有效值后将其从欧芹中排除(使其为只读)。但是如果用户清除了它,我需要删除excluded data属性,并将parsley重新绑定到表单。所有这些我都在做,但好像是a。“排除”不是实际删除的,或b。欧芹不需要再包扎。下面是一些代码: var handleValidation = function($form, type){ //this works for the initial validation. Meaning

我有一项任务要求我使用欧芹选择性地验证输入,然后在输入有效值后将其从欧芹中排除(使其为只读)。但是如果用户清除了它,我需要删除excluded data属性,并将parsley重新绑定到表单。所有这些我都在做,但好像是a。“排除”不是实际删除的,或b。欧芹不需要再包扎。下面是一些代码:

var handleValidation = function($form, type){
            //this works for the initial validation. Meaning it will return
            //false the first time (before I add/remove the excluded data attr)
            var formId =  $form.attr('id');
            var valid = $('#' + formId).parsley().validate({group: ""+type + "-validation", force: true});
            return valid;
};

var reBindParsley = function(parsleyDef,formId){
        $('#' + formId).parsley().destroy();
        parsleyDef();
    };

    $clearIcon.click(function(){
        //find input traversing the dom
        $input.prop("readonly", false); //this works fine
        $input.removeData('parsley-excluded'); //not sure if this is needed
        $input.removeAttr('data-parsley-excluded'); //this gets removed from the visual representation of the DOM, 
                                                 //but when i call validation on it, it's as if it's still there
        reBindParsley();
    })

//this will handle validating the input
$myInput.click(function(){
    var valid = handleValidation($form, type);
    if(valid){
        makeReadOnly() //adds $myInput.attr('data-parsley-excluded', true);
        reBindParsley(parsleyFunction, form);
    }
});
因此,在clearIcon click事件中调用代码后,在我下一次单击输入时,它应该调用handleValidation(),如果值无效(就像第一次一样),但无效,则返回false。我在firefox调试器中检查了DOM的可视化表示,排除的数据不在那里


非常感谢您的帮助

这不是100%的事情,但有一个更简单的方法

$input.removeData('parsley-excluded')
不需要,调用
destroy也不需要

var formId=$form.attr('id');var valid=$('#'+formId).parsley…
只是
$form.parsley…


只需将其添加到表单的排除列表
[readonly]
,您就可以开始了。否则,请发布一个工作提琴。

您是否有一个JSFIDLE,我们可以使用它来重现此问题并进行调试?哇,这是一个更优雅的解决方案,谢谢!真不敢相信我没想到