Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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 - Fatal编程技术网

Javascript jQuery中连接到单选按钮的特定输入验证

Javascript jQuery中连接到单选按钮的特定输入验证,javascript,jquery,Javascript,Jquery,我编写这段代码是为了对注册表中class=req的输入执行实时检查,除了这部分之外,它都可以正常工作 如果用户选择Private,则输入id=pIVA的类保持class=noreq;相反,如果用户选择Corporate,class=req中的类更改,并且所有后续控件现在都被激活,则仅当字段为:11位时才接受该字段,否则将禁用submit按钮并显示错误。通过这种方式,问题是如果用户返回到Private:手动删除之前的错误(如果有),并且类正确更改为class=noreq,并且应该发生的是,如果用户

我编写这段代码是为了对注册表中class=req的输入执行实时检查,除了这部分之外,它都可以正常工作

如果用户选择Private,则输入id=pIVA的类保持class=noreq;相反,如果用户选择Corporate,class=req中的类更改,并且所有后续控件现在都被激活,则仅当字段为:11位时才接受该字段,否则将禁用submit按钮并显示错误。通过这种方式,问题是如果用户返回到Private:手动删除之前的错误(如果有),并且类正确更改为class=noreq,并且应该发生的是,如果用户清除输入或插入任何字母而不是数字,则不应显示错误。相反,问题在于该控件仍然处于活动状态,好像该类将是class=req

有人能解释一下错误在哪里吗

功能需求{ 函数adderrrmsg,inputID{ $'subButton'.prop'disabled',true; $'err'+inputID.fadeIn500.htmlerrMsg; $'err'+inputID.css'background-color','E3BFC0'; $+inputID.css'background-color','E3BFC0'; } 函数removeErrinputID{ $'subButton'.prop'disabled',false; $'err'+inputID.fadeout 500; $+inputID.css'background-color','inherit'; } 函数oneRegex regex、inputValue、errMsg、inputID{ if!regex.testinputValue{ AdderRRMsg,inputID; } 否则{ 去除纹状体; } } /*仅限CHKS.req*/ $'.err'.hide; $'.req'。在“输入”上,函数{ var inputID=$this.attr'id'; var inputValue=$this.val; var valueLenght=$this.val.length; 开关输入{ 案例pIVA: oneRegex/^[0-9]{11}$/,inputValue,'Invalid partita IVA',inputID; 打破 } }; } 函数主语类型{ /*主题类型*/ $'.subjectTypeRadio'。单击,函数{ var$subjectType=$this.val;//1->PF | 2->PG console.log$subjectType; 如果$subjectType==2{ $'pIVA'。删除类'noreq'。添加类'req'; $'resInfoTitle'.html'Sede legale'; } 否则{ $'pIVA'。删除类'req'。添加类'noreq'; 函数removeErrinputID{ $'subButton'.prop'disabled',false; $'err'+inputID.fadeout 500; $+inputID.css'background-color','inherit'; } 去除“皮瓦”; $'resinfo title'.html'Residenza/domicilio'; } reqChk;//回调控制*.req字段的函数 }; } 输入{ 显示:block;} 标签{ 显示:内联块;} $document.readyfunction{ reqChk; 主题类型; }; 私有的 公司的 第四部分
选择Corporate时,需要删除添加到输入框中的事件处理程序。因此,当选择Private单选按钮时,事件处理程序仍然绑定到输入框,因此它的行为是这样的。您需要在$'.err.hide之前删除“on”事件处理程序;行以确保在应用noreq类时删除输入框的事件处理程序

        /* CHKS .req ONLY */
        $('.noreq').off('input'); // Make sure the on event handler is removed from noreq class input.
        $('.err').hide();
        $('.req').on('input', function () {
            var inputID = $(this).attr('id');
            var inputValue = $(this).val();
            var valueLenght = $(this).val().length;

            switch (inputID) {
                case "pIVA":
                    oneRegex(/^[0-9]{11}$/, inputValue, 'Invalid partita IVA', inputID);
                    break;
            }
        });
.关正是我要找的方法,伙计!非常感谢