Acrobat 的日期提取 JavaScript 不起作用
详情如下:
我需要什么代码才能从值为 101219488926
的字段中提取 12
、26
和 48
code> 然后以 MM/DD/YY
? 格式显示(因此在本例中,新值需要为 12/26/48
)
这是长版本:
我使用的是磁条阅读器,它从刷卡(驾驶执照)中获取信息,然后使用该信息自动填充 PDF 中的某些字段(名字、姓氏、出生日期等)。
一切正常,但有一个例外:出生日期。即使这在技术上也可行,但值的格式如下(假设此人的出生日期是 1948 年 12 月 26 日):
101219488926
我需要的是:月份 (12)、日期 (26) 和年份 (19 48)从那个长数字中剥离出来,然后转换为以 MM/DD/YY
格式显示
在 Acrobat 之外,这似乎工作得很好:
var dob = 101219488926;
trimmonth = dob.substring(2,4);
trimday = dob.substring(10,12);
trimyear = dob.substring(6,8);
dob.value = trimmonth + "/" + trimday + "/" + trimyear;
有什么建议吗?
Here's the breakdown:
What code do I need to extract the 12
, 26
, and 48
from a field whose value is 101219488926
and then display it in the format MM/DD/YY
? (So in this case, the new value would need to be 12/26/48
)
Here's the long version:
I'm using a mag-stripe reader that takes information from the swiped card (a driver license) and then uses that info to auto-populate certain fields in a PDF (first name, last name, date of birth, etc).
Everything works fine, with one exception: the date of birth. Even that does technically work, but the value is in this format (assuming the person's DOB is 26 December 1948):
101219488926
What I need is: the month (12), day (26), and year (1948) stripped out of that long number, then converted to display in the format MM/DD/YY
Outside of Acrobat, this seems to work just fine:
var dob = 101219488926;
trimmonth = dob.substring(2,4);
trimday = dob.substring(10,12);
trimyear = dob.substring(6,8);
dob.value = trimmonth + "/" + trimday + "/" + trimyear;
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在那里的代码不应该工作 -
substring
是一个String
函数,因此您需要将您拥有的数字转换为字符串使其可用。设置dob.value
也是可疑的,因为dob
是一个Number
,而数字没有value
属性。当然,很明显您没有显示您尝试过的实际代码,但类似这样的代码可能会起作用:
The code you have there shouldn't work -
substring
is aString
function, so you would need to convert that number you have to a string for it to be available. Settingdob.value
is also suspect, sincedob
is aNumber
, and numbers do not have avalue
property.Of course, it's obvious that you're not showing the actual code you have tried, but something like this would probably work: