Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.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 带表达式的函数不起作用_Javascript_Html - Fatal编程技术网

Javascript 带表达式的函数不起作用

Javascript 带表达式的函数不起作用,javascript,html,Javascript,Html,我在chrome上测试了它,当时它工作了,但现在不行了。你能告诉我为什么吗?如有任何建议,将不胜感激。我也在explorer中进行了测试,结果是一样的。 代码如下: function checkName() { var alphaExp = /^[a-zA-Z\-]+$/; var nume = document.getElementById('nume'); var pren = document.getElementById('pren'); if (num

我在chrome上测试了它,当时它工作了,但现在不行了。你能告诉我为什么吗?如有任何建议,将不胜感激。我也在explorer中进行了测试,结果是一样的。 代码如下:

function checkName() {
    var alphaExp = /^[a-zA-Z\-]+$/;
    var nume = document.getElementById('nume');
    var pren = document.getElementById('pren');

    if (nume.value.match(alphaExp) && pren.value.match(alphaExp) && nume.value.length >= 2 pren.value.length >= 2) {
        return true;
    } else {
        alert("Numele si prenumele trebuie sa contina doar litere si sa aiba mai mult de 2 caractere ! ");
        return false;
    }
}

工作是什么?怎么不再做了?你能把代码简化为只包含相关的部分吗?我把代码简化为Bergi。该函数必须检查我是否根据该表达式键入名称。您缺少一个&&。还有,你把什么价值观放进去,结果出乎意料?非常感谢你,伯吉。我真不敢相信我竟如此盲目,竟看不出那个错误。