我如何添加分钟,使它们变成小时?

How do I add minutes so they turn into hours?

这可能是一个简单的问题,但我如何添加分钟以便它们变成小时,即如果您添加 30 分钟、30 分钟和 30 分钟,答案将是 1 小时 30 分钟?

到目前为止,我的总分钟数是:

         function findTotalHours(){
var arr = document.getElementsByName('hours');
var tot=0;
for(var i=0;i<arr.length;i++){
    if(parseInt(arr[i].value))
        tot += parseInt(arr[i].value);
}
document.getElementById('totalHoursv').value = tot;
        }


function findTotalMins(){
   var arr = document.getElementsByName('minutes');
   var tot=0;
   for(var i=0;i<arr.length;i++){
    if(parseInt(arr[i].value))
        tot += parseInt(arr[i].value);
       }
document.getElementById('totalMins').value = tot;
     }

我创建了一个 js fiddle 来显示无法正常工作的 table...即给出 90 分钟的答案

https://jsfiddle.net/Vicky1984/kLurp45y/9/

非常感谢任何建议,我是 javascript

的新手

谢谢

function findTotalHours(){
   var arr = document.getElementsByName('hours');
   var tot=0;
   for(var i=0;i<arr.length;i++){
      if(parseInt(arr[i].value))
        tot += parseInt(arr[i].value);
   }

   return tot;
}
function findTotalMins(){
  var arr = document.getElementsByName('minutes');
  var tot=0;
  for(var i=0;i<arr.length;i++){
    if(parseInt(arr[i].value))
        tot += parseInt(arr[i].value);
  }
  return tot;
}

function calculateAllocation(){
 var mins = findTotalMins();
 var hrs = findTotalHours();

 hrs = hrs + (mins-mins%60)/60;
 mins = mins%60;

 document.getElementById('totalHoursv').value = hrs;
 document.getElementById('totalMins').value = mins;
}

在 onblur 事件中为小时和分钟输入字段调用 calculateAllocation()

演示: https://jsfiddle.net/kLurp45y/19/