【问题标题】:Adobe Acrobat 2017 Javascript is null?Adobe Acrobat 2017 Javascript 为空?
【发布时间】:2018-08-10 15:57:19
【问题描述】:

在这段代码中:

this.getField("myField").value == null;
this.getField("myField").value === null;
typeof this.getField("myField").value == null;
typeof this.getField("myField").value === null;
this.getField("myField").rawValue === null;
this.getField("myField").formattedValue === "";
this.getField("myField").isNull;
this.getField("myField").isNull == True;

以上所有内容都将“null”替换为“Null”、封装的“Null”和“未定义”。

在每种情况下,我得到的只是:

TypeError: this.getField(...) is null
23:Field:Blur

如何查看字段是否为空?我不想使用默认值,因为不是表单上的每个字段都需要使用并且应该可以为空。

【问题讨论】:

    标签: javascript adobe acrobat


    【解决方案1】:

    如果您收到该错误,那是因为 this.getField("myField") 本身正在返回 null。因此,任何尝试对返回的属性使用属性都会失败。

    听起来你需要一个null 守卫:

    var field = this.getField("myField");
    if (field !== null) }
        // use `field.value` here...
    }
    

    【讨论】:

    • 我刚刚尝试过这种方法... console.show();var checkNull = this.getField("myField"); if(checkNull !== null){ }else{ console.println("它必须是 null...");这是输出: TypeError: this.getField(...) is null 23:Field:Blur
    • @blainechristian - 这非常很奇怪。普通的 JavaScript 不会那样做,一定是一些奇怪的 Adob​​e 东西(或者错误来自不同的代码)。
    【解决方案2】:

    一般...意味着您使用应用程序而不是库来创建表单... PDF 字段值永远不会为空。空字段具有长度为零的字符串作为默认值。要测试该字段是否为空,请使用...

    if (this.getField("myField").value.length == 0) {
        // do something 
    }
    else {
        // it has a value
    }
    

    if (this.getField("myField").value == "") {
        // do something 
    }
    else {
        // it has a value
    }
    

    【讨论】:

    • 谢谢。 Acrobat 的关键是 field.value.length,而不仅仅是我尝试的 field.length。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多