PDF Javascript问题

时间:2017-04-11 12:58:21

标签: javascript pdf default

创建一个交互式pdf文档,该文档应允许用户将注释填写到需要发送的任何人。

实施例: 嗨[你的名字在这里],

应填写如下: 嗨,奥利弗贝克,

现在我一直在使用这段代码确保默认文字在点击后立即消失

ON FOCUS

if(event.target.value == event.target.defaultValue){
    event.target.value = "";
}

ON BLUR

if(event.target.value == ""){
    event.target.value = event.target.defaultValue;
}

现在默认文本消失了我喜欢的方式,但是我想保留已填写的值后面的逗号。

我有一个编号的菜鸟,所以我请求你的帮助。

//<Document-Level>
//<ACRO_source>highlight</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:highlight ***********/
var rths = app.runtimeHighlight ;
app.runtimeHighlight = false ;
//</ACRO_script>
//</Document-Level>

//<AcroForm>
//<ACRO_source>Date:Annot1:OnFocus:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Date:Annot1:OnFocus:Action1 ***********/
if(event.target.value == event.target.defaultValue){
    event.target.value = "";
}
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>Date:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Date:Annot1:OnBlur:Action1 ***********/
if(event.target.value == ""){
    event.target.value = event.target.defaultValue;
}
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>Location:Annot1:OnFocus:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Location:Annot1:OnFocus:Action1 ***********/
if(event.target.value == event.target.defaultValue){
    event.target.value = "";
}
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>Location:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Location:Annot1:OnBlur:Action1 ***********/
if(event.target.value == ""){
    event.target.value = event.target.defaultValue;
}
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>Student name:Annot1:OnFocus:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Student name:Annot1:OnFocus:Action1 ***********/
if(event.target.value == event.target.defaultValue){
    event.target.value = "";
}
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>Student name:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Student name:Annot1:OnBlur:Action1 ***********/
if(event.target.value == ""){
    event.target.value = event.target.defaultValue;
}
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>Time:Annot1:OnFocus:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Time:Annot1:OnFocus:Action1 ***********/
if(event.target.value == event.target.defaultValue){
    event.target.value = "";
}
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>Time:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Time:Annot1:OnBlur:Action1 ***********/
if(event.target.value == ""){
    event.target.value = event.target.defaultValue;
}
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>boss's name:Annot1:OnFocus:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:boss's name:Annot1:OnFocus:Action1 ***********/
if(event.target.value == event.target.defaultValue){
    event.target.value = "";
}

//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>boss's name:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:boss's name:Annot1:OnBlur:Action1 ***********/
if(event.target.value == ""){
    event.target.value = event.target.defaultValue;
}
//</ACRO_script>
//</AcroForm>

2 个答案:

答案 0 :(得分:1)

你可以让这更简单。删除onFocus和onBlur脚本,并将以下代码添加到自定义格式脚本中。字段的值将是输入到字段中的任何内容(人名或空字符串),但表单上的外观将是您连接的字符串。在下面的代码中,事件是format事件,因此event.value将是用于生成外观的字符串。事件目标是字段,因此event.target.value是字段的实际值。 if语句只是在填充名称的情况下添加空格,并在空白时正确定位逗号。

if (event.target.value != "") {
    var pad = " ";
}
else {
    pad = "";
}
event.value = "Hi"+pad+event.target.valueAsString +","

空字段将显示&#34;嗨,&#34;。 如果字段值是&#34; Joel Geraci&#34;,字符串&#34;嗨Joel Geraci,&#34;将出现在表格上。

答案 1 :(得分:0)

我不认为你在他们输入输入时显示代码,但不管怎样,为什么不将逗号连接到字符串上?

event.target.value = event.target.value + ','