js代码如何实现时间段判断? 10
现在的代码只能实现按小时判断,我想实现精确到分如何写:比如10:20至11:30.<scriptlanguage="javaScript">now=newDate(),h...
现在的代码只能实现按小时判断,我想实现精确到分如何写:比如10:20至11:30.
<script language="javaScript">
now = new Date(),hour = now.getHours()
if(hour < 9){window.location.href='hello.html'}
else if (hour > 10) {window.location.href='hello.html'}
</script> 展开
<script language="javaScript">
now = new Date(),hour = now.getHours()
if(hour < 9){window.location.href='hello.html'}
else if (hour > 10) {window.location.href='hello.html'}
</script> 展开
1个回答
2016-08-09 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Ball</title>
<style type="text/css">
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
function timeElapse (date)
{
var reg = /^[1-9]$/;
var current = new Date ();
var d = new Date (date.replace (/[^\s\d]/g, '/'));
var disp = Math.abs (current.getTime () - d.getTime ());
var days = Math.floor (disp / 1000 / 60 / 60 / 24);
var hours = Math.floor (disp / 1000 / 60 / 60 % 24);
hours = reg.test(hours) ? "0" + hours : hours;
var minutes = Math.floor (disp / 1000 / 60 % 60);
minutes = reg.test(minutes) ? "0" + minutes : minutes;
var seconds = Math.floor (disp / 1000 % 60);
seconds = reg.test(seconds) ? "0" + seconds : seconds;
var result = "与当前时间相差 <span class=\"digit\">" + days + "</span> 天 <span class=\"digit\">" + hours
+ "</span> 小时 <span class=\"digit\">" + minutes + "</span> 分钟 <span class=\"digit\">" + seconds
+ "</span> 秒";
$ ("#clock").html (result);
TIMEOUT = setTimeout (function ()
{
timeElapse (date);
}, 1000);
}
var TIMEOUT = null;
$ (function ()
{
var txt = $ (":text");
$ (":button").click (function ()
{
clearTimeout (TIMEOUT);
timeElapse (txt.val ());
})
})
</script>
</head>
<body>
<input type="text" />
<button>test</button>
<div id="clock"></div>
</body>
</html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Ball</title>
<style type="text/css">
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
function timeElapse (date)
{
var reg = /^[1-9]$/;
var current = new Date ();
var d = new Date (date.replace (/[^\s\d]/g, '/'));
var disp = Math.abs (current.getTime () - d.getTime ());
var days = Math.floor (disp / 1000 / 60 / 60 / 24);
var hours = Math.floor (disp / 1000 / 60 / 60 % 24);
hours = reg.test(hours) ? "0" + hours : hours;
var minutes = Math.floor (disp / 1000 / 60 % 60);
minutes = reg.test(minutes) ? "0" + minutes : minutes;
var seconds = Math.floor (disp / 1000 % 60);
seconds = reg.test(seconds) ? "0" + seconds : seconds;
var result = "与当前时间相差 <span class=\"digit\">" + days + "</span> 天 <span class=\"digit\">" + hours
+ "</span> 小时 <span class=\"digit\">" + minutes + "</span> 分钟 <span class=\"digit\">" + seconds
+ "</span> 秒";
$ ("#clock").html (result);
TIMEOUT = setTimeout (function ()
{
timeElapse (date);
}, 1000);
}
var TIMEOUT = null;
$ (function ()
{
var txt = $ (":text");
$ (":button").click (function ()
{
clearTimeout (TIMEOUT);
timeElapse (txt.val ());
})
})
</script>
</head>
<body>
<input type="text" />
<button>test</button>
<div id="clock"></div>
</body>
</html>
追问
好复杂,有没简单一点的?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询