我有这个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;
}
}
谢谢!
答案 0 :(得分:1)
您的代码段中有一个使用正则表达式的函数
一个javaScript regExp reference给你。
感谢@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;
}
}
我想它应该起作用
答案 1 :(得分:0)
\ s表示空格 *表示任何数字 ”“这是空的 “”这也是
答案 2 :(得分: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!