Javascript 的全局变量 (Acrobat Reader)
我有一个 PDF 表单,我试图在文档级 Javascript 编辑器中声明一个全局变量...我正在使用
global.myVariable = "0";
,然后在表单中的一个字段上运行代码:
if(myVariable == "0"){
app.alert("Hello!");
myVariable = "1";
}
这样它只会带来提高警报一次。然而,每次我在任何领域输入任何内容时,它都会出现,这很烦人。请指教!
I have a PDF form and I'm trying to declare a global variable in the Document-level Javascript 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过执行以下操作在任何地方声明全局变量:
myVariable = 1;
但是,如果您在最顶层范围中声明变量,则是最安全的:
var myVariable = 1;
您必须记住的唯一问题是确保您不会在其他任何地方覆盖
myVariable
。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.如果将变量声明为 global.myVariable,则需要将 if 语句编写为:
if you declare the variable as global.myVariable you will need to write your if-statement as: