Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.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/9/csharp-4.0/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,我无法找到我的代码不能正常工作的原因 我有这个功能: function checkIt(input_name, input_value){ if (input_name === 'firstname') { y = regs[0]; } else if (input_name === 'lastname') { y = regs[1]; } else if (input_name === 'phone') { y = regs[2];

我无法找到我的代码不能正常工作的原因

我有这个功能:

function checkIt(input_name, input_value){
   if (input_name === 'firstname') {
       y = regs[0];
   } else if (input_name === 'lastname') {
       y = regs[1];
   } else if (input_name === 'phone') {
       y = regs[2];
   } else if (input_name === 'mail') {
       y = regs[3];
   } else {
       y = regs[4];
   }
   z = input_value.match(y1);

   if (z !== null) {
       rez = true;
   } else {
       rez = false;
   }

   return rez;
}
然后我做这个:

$(document).on("blur", "input[name=firstname]", function(){
    p = $(this).prop("name");
    q = $(this).val();
    r = checkIt(p, q);
    if (r) {
         // something
    } else {
         // something
    }
});
我的问题是我的代码在第一模糊上不起作用。它开始在第二个模糊上执行,并且一切都完美…:/

尝试在没有参数名称的情况下使用on(“模糊”、“输入”和“函数”),因为您有带有此输入属性的var p

 $(document).on("blur", "input", function(){
        p = $(this).prop("name");
        q = $(this).val();
        r = checkIt(p, q);
        if (r) {
             // something
        } else {
             // something
        }
    });

只有一件事:
z=input_value.match(y1)
你是指
y
而不是
y1
?顺便说一句,为什么要使用全局变量?控制台窗口告诉你什么(点击F12)?什么是regs数组,checkIt函数应该做什么,检查所有必需的字段是否都已填充?thx很多次,它重新更正并且工作正常。。你指的是哪个全局变量?