1
JavaScript Proを使用しています(JavaScriptを使用しています)、これらのフォームフィールドを正しく動作させようとしています。ユーザーはいくつかのフィールドに時間の長さ(MM:ss)を入力し、最後に合計時間をMM:ssとして表示する必要があります。JavaScript - 分入力:秒と合計の合計
私は総時間
//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)。
アイデア?
コードからわかるように、最初の総数( 'v1'の値)が得られれば、あなたが望むものは不可能です。最初は合計秒数が必要です(分単位でグループ化できます)。実際には、最初の秒数を取得してください。コードを編集してください。それで明らかになります。 (フィールドは「合計秒」と呼ばれる)。あるいは、別のケースでは、あなたは分を浮動小数点数にしていますか? – victor175