这是一款小时和分钟时间转换程序,用户输入值后点击按钮即可转换,实用js转换代码,结合自己的需求来修改即可。
<SCRIPT LANGUAGE="JavaScript"> <!-- Begin function checkInt(str) { if (!str) return 0; var ok = ""; for (var i = 0; i < str.length; i++) { var ch = str.substring(i, i+1); if (ch < "0" || "9" < ch) { alert("Only integer input is allowed!\n\n" + parseInt(ok) + " will be used because '" + str + "' is invalid.\nYou may correct " + "this entry and try again."); return parseInt(ok); } else ok += ch; } return parseInt(str); }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) function checkDecimal(str) { if (!str) return 0; var ok = ""; for (var i = 0; i < str.length; i++) { var ch = str.substring(i, i+1); if ((ch < "0" || "9" < ch) && ch != '.') { alert("Only numeric input is allowed!\n\n" + parseFloat(ok) + " will be used because '" + str + "' is invalid.\nYou may correct " + "this entry and try again."); return parseFloat(ok); } else ok += ch; } return str; }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) function makeHours(form) { hour = (checkInt(form.hour.value)); // validates input min = (checkInt(form.min.value)); // sets invalid input to 0 sec = (checkInt(form.sec.value)); return (hour + min/60 + sec/3600); } function makeTime(form) { num = (checkDecimal(form.hourtotal.value)); // validates input if (num) { form.hour.value = parseInt(num); num -= parseInt(num); num *= 60; form.min.value = parseInt(num); num -= parseInt(num); num *= 60; form.sec.value = parseInt(num); } }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) // End --> </script> <a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr> <!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。--> <script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script> <script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script> <form name="timeconverter"> <table border=1> <tr> <td>time:</td> <td> <input type=text name=hour size=3 maxlength=3>小时 <input type=text name=min size=3 maxlength=3>分 <input type=text name=sec size=3 maxlength=3>秒 </td> </tr> <tr> <td>hours:</td> <td> <input type=text name=hourtotal size=10> </td> </tr> <tr> <td colspan=2 align=center> <input type=button nametoHours value="Time to Hours" onClick="this.form.hourtotal.value=makeHours(this.form);"> <input type=button name=toTime value="Hours to Time" onClick="makeTime(this.form);"> </td> </tr> </table> </form>
本文来自武鸣人网站,转载请注明出处