使用javascript

时间:2016-02-29 21:51:35

标签: javascript

我有一个表单,它接收输入的信息并在另一页上显示该信息。设置表单的方式是用户输入运行时间,该运行时间用冒号分隔,并以相同的格式输入惩罚时间。处理和显示数据的方式没有任何前导零。例如,对于运行时间,用户输入01:00和罚分时间00:05。输出该信息的方式是1:5,我希望输出信息的方式是01:05。我知道没有javascript函数总是保留前导零,但我似乎无法弄清楚如何实现这一点。

这是我的代码。

<script type = "text/javascript">
function calculate()
{


<!-- Variables -->
var dfbrun = document.getElementById("dfb_run").value;
var dfbpen = document.getElementById("dfb_pen").value;
var splitdfbrun = dfbrun.split(':');
var splitdfbpen = dfbpen.split(':');
var dfbmin;
var dfbsec;
var dfbtot;

<!-- DFB Time input -->
dfbmin = parseFloat(splitdfbrun[0].slice(-4)) +    parseFloat(splitdfbpen[0].slice(-4))
dfbmin = dfbmin%60;

dfbsec = parseInt(splitdfbrun[1].slice(-2)) + parseInt(splitdfbpen[1].slice(-2))
dfbsec = dfbsec%60;

alert(+dfbmin+ ':' +dfbsec)
dfbtot = +dfbmin+ ':' +dfbsec;
document.getElementById("dfb_com").value = dfbtot;
}

jQuery(function ($) {
         $.mask.definitions['~']='[+-]';
        $('.run').mask('99:99');
        $('.penalty').mask('99:99');

    })
</script>

<form method = "GET" action = "RodeoDisplay.php" target = "RodeoDisplay.php">
<table>
<tr> 
    <td> Site: <input type = "text" value = "DFB" readonly = "true" size = "4"> </td>
    <td> Run Time: <input type = "text" size = "5" id = "dfb_run" class = "run" name = "dfb_run">
    <td> Penalty: <input type = "text" class = "penalty" size = "5" id = "dfb_pen"> </td>
    <td> Completed Time: <input type = "text" readonly = "true" size = "5" id = "dfb_com"> </td>
</tr>
</table>

使用时间功能会更好吗?

0 个答案:

没有答案