我正在使用 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/