由于某种原因似乎无法使此功能正常工作,请阅读大约 10000 个文档大声笑
谢谢!
您对数字的 if 语句的逻辑有点差。正如我在评论中提到的
if(inputtxt.value.match(numbers))
应该
if(!numbers.test(inputtxt.value)) {
alert('Please input numeric characters only');
document.reasoning.mpn.focus();
isValid = false;
}
对于您的文档,您正在尝试使用mpn
名称验证字段,但据我所知,您没有检索它们。看到只有 1 个 mpn 字段,您可能想要使用 id,因此您不必如下迭代。尝试以下操作:
isValid = isValid && all(document.getElementsByName("mpn"), function(ele) {
if(numbers.test(ele.value)) {
return true;
} else {
alert('Please input numeric characters only');
ele.focus()
return false;
}
});
我不想输入代码,all
但假设它类似于_.all
underscorejs。