开发者

Global Variables for Javascript (Acrobat Reader)

I have a PDF form and I'm trying to declare a global variable in the Document-level Javascrip开发者_Python百科t editor... I'm using

global.myVariable = "0";

and then on a field in the form, I'm running the code:

if(myVariable == "0"){

  app.alert("Hello!");

  myVariable = "1";

}

So that it only brings up the alert once. However, it's bringing it up every time I enter anything into any field, which is annoying. Please advise!


You can declare a global variable anywhere by doing:

myVariable = 1;

However it's safest if you declare your variable in the top-most scope:

var myVariable = 1;

The only issue you have to remember is to make sure you don't override myVariable anywhere else.


if you declare the variable as global.myVariable you will need to write your if-statement as:

if(global.myVariable === "0"){

    app.alert("Hello!");

    global.myVariable = "1";

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜