JavaScript - 输入分钟 :seconds and sum totals

标签 javascript pdf acrobat

我正在使用 Acrobat Pro 9(使用 JavaScript),并且正在尝试使这些表单字段正常工作。用户需要在几个字段中输入持续时间(MM:ss),然后在底部将总持续时间相加,也显示为 MM:ss。

我使用此代码来创建总时间

//Get the total from hidden field
var v1 = getField("Total minutes").value;

// Define a constant to be used below:
var numSecondsInMinute = 60;

// The total number of seconds:
var numSeconds = v1*60;

// Extract the number of minutes from the total number of seconds - rounded down:
var numMinutes = Math.floor(numSeconds / numSecondsInMinute);

// Subtract the extracted number of minutes (converted to seconds) from the total number of 
// seconds to get the remaining number of seconds:
numSeconds -= (numMinutes * numSecondsInMinute);

// Build a string from the final number of minutes and number of seconds in (MM:SS) format:
var finalTime = "(" + numMinutes + ":" + numSeconds + ")";

// Display the final time:
event.value=finalTime;

但这无助于获取各种 MM:ss 字段的总数(例如 1:30 一分半钟,或 2:15,或 7:00)。

有什么想法吗?

最佳答案

您可以使用 Acrobat JavaScript util.scand() 方法将输入到各个 MM:ss 字段中的字符串转换为 JavaScript Date 对象,执行数学运算,然后使用 util.printd( ) 方法,然后将该值设置为“总分钟数”值。

关于JavaScript - 输入分钟 :seconds and sum totals,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38105792/

相关文章:

javascript - 使用 JavaScript 追加和选择多个 div

javascript - 尝试匿名登录 Firebase 时,对引荐来源网址的请求被阻止

iphone - iOS:从 UIView 创建 PDF

pdf - 如何使用非 ASCII 编码从 PDF 中剪切粘贴?

c++ - 如何使用 C++ 从特定文件中提取 X.509 证书(DER 编码)?

javascript - while(鼠标在某个边界框内)做某事; -- 在 JavaScript 中

javascript - 不要直接改变状态。使用 setState() react/no-direct-mutation-state

java - 在 Java EE 中将生成的 PDF 存储在何处

c# - iTextSharp - 从 PictureBox 控件中获取图像并将其插入到 PDF 文件中

twitter-bootstrap - Bootstrap 3 Accordion 面板不会打印