導航:首頁 > 編程語言 > js預定時間段

js預定時間段

發布時間:2023-05-19 21:53:00

1. js代碼如何實現時間段判斷

<! 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>

2. js固定時間段觸發事件

你所定義的時間,是想用本地時間還是用伺服器事件,


如果用本地時間版

vartoday=newDate();
varhour=today.getHours();
if(hour>=8&&hour<9){
//todosomething
}


如果用伺服器時權間

vartoday=newDate(${serverTime});//將伺服器時間輸出到這里
varhour=today.getHours();
if(hour>=8&&hour<9){
//todosomething
}

3. JS如何計算系統當前的時間與預定時間的倒計時

<html>
<head>
<title>倒計時</title>
</head><BODY>
<!--將以下代碼加入HTML的<Body></Body>之間-->

<SCRIPT language=JavaScript1.2>
function setcountdown(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}
setcountdown(2006,11,30)
var occasion="2006年11月30日"
var message_on_occasion="盼望已久的時刻終於來到了!"
var countdownwidth='480px'
var countdownheight='20px'
var countdownbgcolor='tan'
var opentags='<font face="宋體"><small>'
var closetags='</small></font>'
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''
function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countdownie") : countdownie
countdown()
}

if (document.all||document.getElementById)
document.write('<span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span>')

window.onload=start_countdown

function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+message_on_occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+closetags
return
}
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+"時間已經過了!"+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Occasion already passed! "+closetags
return
}
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"還有 "+dday+ " 天, "+dhour+" 小時, "+dmin+" 分, "+dsec+" 秒 就是 "+occasion+closetags
}
setTimeout("countdown()",1000)
}
</SCRIPT>
<ILAYER id=countdownnsmain visibility="hide" bgColor="&{countdownbgcolor};"
height="&{countdownheight};" width="&{countdownwidth};"><LAYER
id=countdownnssub height="&{countdownheight};"
width="&{countdownwidth};" top="0" left="0"></LAYER></ILAYER>
</body></html>

4. 求一段js代碼。設置時間段內執行代碼

function clock(){
var curr = new Date();
var time = curr.getHours();
if ( time >= 10 && time <16 ){
//do someting
}
}

5. js 如何控制文本域輸入內容在一定間隔時間段才觸發事件查詢相關數據

可以用onpropertychange, 這個函數稿譽皮是輸入鍵差框每鍵一鍵就觸發,可以在裡面判斷一下 輸入的位數,或規定值,,再虛姿提交後台查詢。。

6. 求js指定時間范圍對頁面進行刷新代碼

10到20分鍾刷新頁面:
setTimeout("location.reload();",parseInt(Math.random()*600000)+600000);

7. 求JS彈窗代碼,能再規定時間段內彈出

<SCRIPT LANGUAGE="JavaScript">
var myDate = new Date();
myDate.getYear(); //獲取當前年份(2位)
myDate.getFullYear(); //獲取完整的年份(4位,1970-????)
myDate.getMonth(); //獲取當前月份(0-11,0代表1月)
myDate.getDate(); //獲取當前日(1-31)
myDate.getDay(); //獲取當前星期X(0-6,0代表星期天)
myDate.getTime(); //獲取當前時間(從1970.1.1開始的毫秒數)
myDate.getHours(); //獲取當前小時數(0-23)
myDate.getMinutes(); //獲取當前分鍾數(0-59)
myDate.getSeconds(); //獲取當前秒數(0-59)
myDate.getMilliseconds(); //獲取當前毫秒數(0-999)
myDate.toLocaleDateString(); //獲取當前日期
var mytime=myDate.toLocaleTimeString(); //獲取當前時間
myDate.toLocaleString( ); //獲取日期與時間
if (mytime<"23:00:00" && mytime>"04:00:00"){
window.open("你要打開的網站");
}
</SCRIPT>

8. html用JS怎麼實行定時間刷新頁面

js刷新頁面可緩腔鉛以用定時器加reload去實現。

例:
setInterval(function(){
window.location.reload();
},5000);

這樣是每隔五圓橘秒刷新一次擾好當前頁面

9. js配送時間按照半小時分段

用setTimeout函數啊搏嫌,你可以散蘆設置時間,運行。
所有的訂單都先放進一個站基掘手裡面,或者資料庫,或者表。都行啦。
然後每隔半小時檢查一遍符合條件的數據根據需要執行相應的方法不就行了。

閱讀全文

與js預定時間段相關的資料

熱點內容
wokrNC和UG編程哪個好 瀏覽:487
愛奇藝隨刻文件名 瀏覽:40
wps是怎麼壓縮文件 瀏覽:986
dos配置文件名 瀏覽:582
java軟體工程師做什麼 瀏覽:897
3dmax導出ive文件 瀏覽:464
數據重復性好是什麼意思 瀏覽:166
如何查找電腦文件使用歷史記錄 瀏覽:821
linux可以運行exe的文件嗎 瀏覽:935
庫幣是哪個國家的app 瀏覽:201
大智慧internet文件夾有哪些文件 瀏覽:89
編程培訓課程哪個排名好 瀏覽:124
我的cad怎麼沒顯示文件選項卡 瀏覽:952
命令行當前是哪個資料庫 瀏覽:588
為什麼appstore打開空白 瀏覽:574
選貨車軟體什麼app最好 瀏覽:577
psv仙境傳說ace如何降級版本 瀏覽:460
杭州哪裡學少兒編程比較好 瀏覽:642
什麼網站可以自己翻唱歌曲 瀏覽:291
javalist作為參數 瀏覽:176

友情鏈接