0

如果另一个字段包含数据,我有这个 javascript 在我的 PDF 表单中运行良好,可以根据需要设置一个字段。但是,我想让它忽略测试的“0.00”值。但我不知道这/^\s*$/意味着什么,更不用说如何根据我的情况更改脚本了。

var rgEmptyTest = /^\s*$/;
// t is the value to be tested and f is the field to set accordingly
function testMyField (t, f) {
if (rgEmptyTest.test(t)) {
this.getField(f).required = false;         
} else {
this.getField(f).required = true;         
}
}

谢谢!

4

3 回答 3

1

在您的代码中有一个使用正则表达式的函数

为您提供的JavaScript regExp 参考

感谢@j08691的链接解释并让您测试使用的正则表达式(regexr.com/3rf9u)。

您可以像这样更改代码以产生逻辑异常

var rgEmptyTest = /^\s*$/;
var rgTest = /0.00/;
// t is the value to be tested and f is the field to set accordingly
function testMyField (t, f) {
  if (rgEmptyTest.test(t) || rgTest.test(t)) {
    this.getField(f).required = false;         
  } else {
    this.getField(f).required = true;         
  }
}

我想它应该工作

于 2018-06-22T20:12:03.667 回答
0

\s 表示空格 * 表示任何数字 " " 这是空的 " " 这也是

于 2018-06-22T19:41:52.173 回答
0

我想我得到了这个工作:

var rgEmptyTest = /^\s*$/;
var rgTest = /^[0\.00]$/;
// t is the value to be tested and f is the field to set accordingly
function testMyField (t, f) {
if (rgEmptyTest.test(t) || rgTest.test(t)) {
this.getField(f).required = false;         
} else {
this.getField(f).required = true;         
}
}

谢谢@Higor Lorenzon 和@j08691!

于 2018-06-22T21:35:25.137 回答