導航:首頁 > 編程語言 > js計時提交數據

js計時提交數據

發布時間:2023-04-18 16:12:28

❶ 用js實現計時器功能

腳空租坦本說明:
第一步:把如下代碼加入<head>區域中
<SCRIPT language=javascript>
<!--
function generate(form){for(var q=0;q<12;q++){if(document.me.m.options[document.me.m.selectedIndex].value==q){var m2=q+1
}var txt='<!-- 分三步完成全部腳本:\r\n\r\n'
+' 1. 將第一部分粘貼到HTML的HEAD區\r\n'
+' 2. 將OnLoad事件加入BODY標簽內\r\n'
+' 3. 將最後一部分代碼加入BODY區 -->\r\n\r\n'
+'<!-- 第一步: 將如下代碼粘貼到HTML的HEAD區斗桐-->\r\n\r\n'
+'<HEAD>\r\n\r\n<SCRIPT LANGUAGE="JavaScript">\r\n\r\n'
+'<!-- Begin\r\n'
+'var Temp2;\n'
+'var timerID = null;\n'
+'var timerRunning = false;\n'
+'function arry() {\n'
+'this.length = 12;\n'
+'this[0] = 31;\n'
+'this[1] = 28;\n'
+'this[2] = 31;\n'
+'this[3] = 30;\n'
+'this[4] = 31;\n'
+'this[5] = 30;\n'
+'this[6] = 31;\n'
+'this[7] = 31;\n'
+'this[8] = 30;\n'
+'this[9] = 31;\n'
+'this[10] = 30;\n'
+'this[11] = 31;\n'
+'}\n'
+'var date = new arry();\n'
+'\n'
+'function stopclock() {\n'
+'if(timerRunning)\n'
+'clearTimeout(timerID);\n'
+'timerRunning = false;\n'
+'}\n'
+'\n'型飢
+'function startclock() {\n'
+'stopclock();\n'
+'showtime();\n'
+'}\n'
+'\n'
+'function showtime() {\n'
+'now = new Date();\n'
+'var CurMonth = now.getMonth();\n'
+'var CurDate = now.getDate();\n'
+'var CurYear = now.getFullYear();\n'
+'now = null;\n'
+'if ('+document.me.d.options[document.me.d.selectedIndex].value+' < CurDate) {\n'
+'CurDate -= date[CurMonth]; CurMonth++;\n'
+'}\n'
+'if ('+document.me.m.options[document.me.m.selectedIndex].value+' < CurMonth) {\n'
+'CurMonth -= 12; CurYear++;\n'
+'}\n'
+'\n'
+'var Yearleft = '+document.me.y.options[document.me.y.selectedIndex].value+' - CurYear;\n'
+'var Monthleft = '+document.me.m.options[document.me.m.selectedIndex].value+' - CurMonth;\n'
+'var Dateleft = '+document.me.d.options[document.me.d.selectedIndex].value+' - CurDate;\n'
+'\n'
+'document.dateform.a.value = Yearleft;\n'
+'document.dateform.b.value = Monthleft;\n'
+'document.dateform.c.value = Dateleft;\n'
+'\n'
+'timerID = setTimeout("showtime()",1000);\n'
+'timerRunning = true;\n'
+'}\n'
+'/\/ End -->\r\n<\/script>\r\n'
+'<\/H'+'EAD>\r\n\r\n'
+'<!-- 第二步:將OnLoad事件加入BODY標簽內 -->\r\n\r\n'
+'<BO'+'DY Onload="startclock()">\r\n\r\n'
+'<!-- 第三步:將最後一部分代碼加入BODY區 -->\r\n\r\n'
+'<form name=dateform>距離'
+m2+'/'+document.me.d.options[document.me.d.selectedIndex].value+'/'
+document.me.y.options[document.me.y.selectedIndex].value
+'還有\n'
+'<input type=text name=a size=2 value="">年\n'
+'<input type=text name=b size=2 value="">月\n'
+'<input type=text name=c size=2 value="">天\n'
+'</fo'+'rm>\r\n\r\n'
+'<'+'!-- 代碼長度: 1.95 KB --'+'>'
;}document.mail.source.value=txt;document.mail.source2.value=txt;}
//-->
</SCRIPT>

第二步:把如下代碼加入區域中:
<center>
<table border=5 bordercolor=blue borderlight=green>
<tr><td align=center><font size=5 color=red face="Arial, Helvetica, sans-serif"><strong>下面框中為腳本顯示區</strong></font></td></tr>
<tr><td align=center><form name=me> <p><select name=m size=1> <option value=0>January </option> <option value=1>February </option> <option value=2>March </option> <option value=3>April </option> <option value=4>May </option> <option value=5>June </option> <option value=6>July </option> <option value=7>August </option> <option value=8>September </option> <option value=9>October </option> <option value=10>November </option> <option value=11>December </option> </select> <select name=d size=1> <option value=1>1 </option> <option value=2>2 </option> <option value=3>3 </option> <option value=4>4 </option> <option value=5>5 </option> <option value=6>6 </option> <option value=7>7 </option> <option value=8>8 </option> <option value=9>9 </option> <option value=10>10 </option> <option value=11>11 </option> <option value=12>12 </option> <option value=13>13 </option> <option value=14>14 </option> <option value=15>15 </option> <option value=16>16 </option> <option value=17>17 </option> <option value=18>18 </option> <option value=19>19 </option> <option value=20>20 </option> <option value=21>21 </option> <option value=22>22 </option> <option value=23>23 </option> <option value=24>24 </option> <option value=25>25 </option> <option value=26>26 </option> <option value=27>27 </option> <option value=28>28 </option> <option value=29>29 </option> <option value=30>30 </option> <option value=31>31 </option> </select><select name=y size=1> <option value=1999>1999 </option> <option value=2000>2000 </option> <option value=2001>2001 </option> <option value=2002>2002 </option> <option value=2003>2003 </option> <option value=2004>2004 </option> <option value=2005>2005 </option> <option value=2006>2006 </option> <option value=2007>2007 </option> <option value=2008>2008 </option> <option value=2009>2009 </option> </select><br> <input type=button onclick=generate() value=生成代碼 class=yk9><input type=button value=返回 onClick=history.go(-1) name=button class=yk9><p></p></form><form name=mail> <input type=hidden name=scriptname value="Countdown Creator"><input type=hidden name=source2 value><table bgcolor=dedfdf border=1 cellpadding=1 width=396> <tr> <td align=center height=218><textarea name=source rows=12 cols=55 class=yk9></textarea><br> <br> </td> <td> </td> </tr> </table></form></td></tr></table>

❷ JS倒計時頁面代碼(要求讀取伺服器時間)

用JavaScript獲取伺服器時間,然後做頁面倒計時的程序代碼如下:

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml"xml:lang="en"lang="en">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>untitled</title>
<scripttype="text/javascript">
get=function(id){
returndocument.getElementById(id)
}
if(document.all){
window.XMLHttpRequest=function(){
varget=['Microsoft.XMLHTTP','Msxml2.XMLHTTP'];
for(vari=0;i<get.length;i++)
{
try{
returnnewActiveXObject(get[i])
}
catch(e){}
};
};
}
webDate=function(fn){
varHtime=newXMLHttpRequest();
Htime.onreadystatechange=function(){
Htime.readyState==4&&(fn(newDate(Htime.getResponseHeader('Date'))))
};
Htime.open('HEAD','/?_='+(-newDate));Htime.send(null);
}
window.time=newDate();
targetTime=newDate();
time2String=function(t){
with(t)return[getFullYear(),'年',('0'+(getMonth()+1)).slice(-2),'月',('0'+getDate()).slice(-2),'日',('0'+getHours()).slice(-2),':',('0'+getMinutes()).slice(-2),':',('0'+getSeconds()).slice(-2)].join('')
}
int2time=function(m){
m-=(D=parseInt(m/86400000))*86400000;m-=(H=parseInt(m/3600000))*3600000;S=parseInt((m-=(M=parseInt(m/60000))*60000)/1000);
returnD+'天'+H+'小時'+M+'分'+S+'秒'
}
setInterval(function(){
webDate(function(webTime){
get('web').innerHTML=time2String(time=webTime);
})
get('locale').innerHTML=time2String(newDate);
get('time').innerHTML=int2time(targetTime-time);
if((targetTime-time)<0){
get('time').innerHTML='GameOver';
}},1000)
</script>
</head>
<body>
設定時間:2015年06月18日0時0分0秒<br>伺服器時間:<spanid='web'>loading...</span><br>
本地時間:<spanid="locale">loading...</span><br>
倒計時時間:<spanid="time">loading...</span>
<scripttype="text/javascript"charset="utf-8">targetTime=newDate(2015,06,18,00,00,00);</script>
</body>
</html>

註:原理用xmlhttp來獲取伺服器上的時間,後台用js做倒計時顯示到頁面上,由於獲取伺服器時間這個在本地運行不一定能成功,最好是在伺服器上運行!

❸ html如何用JS自動彈出一個DIV

也就先做一個DIV。裡面的內容都做好。
此DIV背後加一個mask層。
把這個DIv默認設置為隱藏。
JS里加一個定時器,每隔一分鍾,設置為這個DIv的css樣式中的display=block

❹ 怎樣用JS實現數據的批量提交

在一個項目中用Excel組件OWC.Spreadsheet在客戶端鏈友導出HTML格式的表格為Excel文件,對於數據量較大的表格導出會造成IE窗口遲喚鏈停止響應,用戶體驗很差。想到三個解決方案: 1、用applet結合jxl實現。暫不考慮。 2、利用類似Ajax請求的機制,非同步調用碼孫一個導出方法,該方法在導出完畢後回調一個callback方法。 3、利用類似Java中的線程機制,直接開一個導出線程即可。

❺ 如何實現JS 計時器

//html
<div>當前時間為:<spanid="timeNow"></span></div><br>
<buttonid="timeBegin">計時開始</button>
<buttonid="timeEnd">計時結束</button>
<buttonid="timeClear">計時清除</button>

//Javascript
<scripttype="text/javascript">
//定義初始值計時器
varcount=0;
vartimer="";
//開始計時
functionBeginTime(){
varbeginBtn=document.getElementById("timeBegin");
beginBtn.onclick=function(){
timer=setInterval(function(){
count++;
document.getElementById("timeNow").innerHTML=count/100;
},10)
}
}
//結束計時
functionEndTime(){
varendBtn=document.getElementById("timeEnd");
endBtn.onclick=function(){
clearInterval(timer);
}
}
//計時清除
functionClearTime(){
varclearBtn=document.getElementById("timeClear");
clearBtn.onclick=function(){
document.getElementById("timeNow").innerHTML="";
count=0;
}
}
BeginTime();
EndTime();
ClearTime();
</script>

思路: 很簡單

  1. 一個盒子來顯示時間, 三個按鈕控制時間 開始 、 結束、 歸零

  2. 定義一個初始值和計時器,點開始計時器初始值不斷增加,點結束停止計時器,點清除把時間盒子清空,初始值歸零即可

  3. 記錄生活的瞬間,分享學習的心得,感悟生活,留住感動,( www.jensonhui.com )

❻ JS時間倒計時並到時自動提交表單,做個考試頁面,登錄後兩個小時答題,要在頁面顯示開始和結束時間

<!DOCTYPEhtml>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>倒計時</title>
<style>
diva{float:left;margin-left:18px;}
.jrotate{
width:80px;
padding:0px;
}
.jrotate>div{
width:36px;
height:36px;
overflow:hidden;
padding:0px;
margin:0px;
margin-right:2px;
float:right;
}
.jrotatedivdiv{
text-align:center;
background:#CCC;
width:36px;
height:36px;
margin:0px;
font-size:36px;
}
.time{
font-size:24px;

}
</style>
<scriptsrc="jq-2.1.0.js"></script>
</head>

<body>
<divstyle="text-align:center;">
<divclass="not-start"style="display:none;">
<h1>考試還未開始</h1>
</div>
<divclass="show-jishi"style="display:none;">
<h1>考試結束倒計時</h1>
</div>
<divclass="show-end"style="display:none;">
<h1>考試已經結束</h1>
</div>
<h1time></h1>
<divstyle="padding-left:36%;">
<a>
<divday>
</div>
<divclass="time">
days
</div>
</a>
<a>
<divhour>
</div>
<divclass="time">
hours
</div>
</a>
<a>
<divminute>
</div>
<divclass="time">
minutes
</div>
</a>
<a>
<divsecond>
</div>
<divclass="time">
seconds
</div>
</a>
<divstyle="clear:both"></div>
</div>
<formaction="#"class="show-jishi">
<div>考試內容在這</div>
</form>

</div>
<script>
functionJrotate(cfg){
cfg=$.extend({},Jrotate.defaults,cfg);
this.init(cfg);
}
$.fn.Jrotate=function(){
return殲吵newJrotate({renderTo:this[0]});//注意這里返回的不是JQ對象
}
Jrotate.prototype={
init:function(cfg){
this.cfg=cfg;
弊清if(!cfg.renderTo)return;
cfg.renderTo=$(cfg.renderTo);
if(cfg.renderTo[0].isJrotate)return;
cfg.renderTo[0].isJrotate=true;
if(cfg.class){
cfg.renderTo.addClass(cfg.class);
}
氏卜侍cfg.showNumber=cfg.showNumber||0;
cfg.showNumber+='';
this.makeDefaultList(Math.max(cfg.startLength,cfg.showNumber.length),cfg.startNumber);
this.setNumber(cfg.showNumber);
},
makeDefaultList:function(len,num){
if(len<1)return;
varcfg=this.cfg;
num=num||0;
num+='';
while(num.length<len){
num='0'+num;
}
varcfg=this.cfg;
for(vari=0;i<len;i++){
if(cfg.renderTo.children('div').length>=cfg.maxLength)return;
cfg.renderTo.prepend(this.makeList(num.charAt(i)));
}
},
setNumber:function(num){
if(num==this.lastNumber)return;
if(isNaN(num))return;
varcfg=this.cfg;
num+='';
varlength=num.length;
varlen=cfg.renderTo.children('div').length;
this.makeDefaultList(Math.max(cfg.startLength,length)-len);
length=Math.max(length,len,cfg.startLength);
while(num.length<length){
num='0'+num;
}
var_this=this;
cfg.renderTo.children('div').each(function(index){
index=length-index-1;
varchar=num.charAt(index);
if(this.showIndex==char)return;
varobj={ele:this,index:index};
setTimeout(function(){_this.gotoIndex(obj.ele,char,1)},5);
});
this.lastNumber=num;
},
gotoIndex:function(ele,index,sts){
ele=$(ele);
varh=ele.children('div:first').height();
varcfg=this.cfg;
ele[0].showIndex=index;
ele.animate({
scrollTop:index*h
},sts&&cfg.speed);
},
makeList:function(num){
num=num||0;
var_this=this;
varul=$("<div>");
for(vari=0;i<10;i++){
varli=$('<div>');
ul.append(li.html(i));
}
setTimeout(function(){_this.gotoIndex(ul,num,0)},2);
returnul;
}
}
Jrotate.defaults={
renderTo:'#div',//顯示效果的對象
startNumber:0,
showNumber:0,
maxLength:2,
startLength:2,
class:'jrotate',//樣式
speed:500//動畫速度
};

varlastTime='2014-05-2412:00:00';//截止時間
varstartTime='2014-05-2316:00:00';//開始時間
vardays=$('[day]').Jrotate();
varhours=$('[hour]').Jrotate();
varminutes=$('[minute]').Jrotate();
varseconds=$('[second]').Jrotate();
vartimes={
day:days,
hour:hours,
minute:minutes,
second:seconds
}


varshowTime;
functionsetTime(){
vardate=newDate().getTime();
if(date<startTimes){
$('.not-start').show();
showTime=startTimes;
}elseif(date>lastTimes){
alert('考試結束');
$('form')[0].submit();
}else{
$('.not-start').hide();
$('.show-jishi').show();
showTime=lastTimes;
}
var_time={}
vart=(showTime-date)/1000|0;//總的秒數
_time.day=t/(60*60*24)|0;//天數
t-=_time.day*60*60*24;
_time.hour=t/(60*60)|0;//小時數
t-=_time.hour*60*60;
_time.minute=t/60|0;//分鍾
_time.second=t-_time.minute*60;//秒數

$('[time]').html(_time.day+'天'+_time.hour+'小時'+_time.minute+'分'+_time.second+'秒');
for(variintimes){
times[i].setNumber(_time[i]);
}
}
vardate=newDate().getTime();
varstartTimes=newDate(startTime).getTime();
varlastTimes=newDate(lastTime).getTime();
if(date>lastTimes){
$('.show-end').show().nextAll().remove();
}else{
setTime();
setInterval(setTime,500);
}
</script>
</body>
</html>

請修改具體的開始時間 和截止時間來展示不同效果 包括未開始 正在進行和已經完畢的處理

❼ js中計時器返回數值

JS可以實現很多java代碼不易完成的功能。這里學習一些js中的計時器事件。

JavaScript 一個設定的時間間隔之後來執行代碼,稱之為計時事件。

主要通過兩個方法來實現:

1.setInterval() - 間隔指定的毫秒數不停地執行指定的代碼。

2.setTimeout() - 暫停指定的毫秒數後執行指定的代碼

並且,這兩個方法都是window對象的方法。

首先,介紹setInterval()方法,該方法值得是間隔一定的毫秒數不停的執行指定的代碼。

語法:window.setInterval(」js代碼,函數等「,毫秒數);

實例1:每三秒彈出一個hello

setInterval(function(){alert("Hello")},3000);

實例2:顯示當前時間,通過按鈕實現時間的停止,開始

<script type="text/javascript">
var myVar;
function startTimer(){
/*setInterval() 間隔指定的毫秒數不停地執行指定的代碼*/
myVar=setInterval(function(){myTimer()},1000);
}
function myTimer()/* 定義一個得到本地時間的函數*/
{
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("demo").innerHTML=t;
}
function stopTimer()
{/* clearInterval() 方法用於停止 setInterval() 方法執行的函數代碼*/
clearInterval(myVar);
}
</script>
setTimeout() 方法

在html或jsp中

<body>
<h4 id="demo"></h4>
<input type="button" onclick="startTimer()" value="開始">
<input type="button" onclick="stopTimer()" value="停止">
</body>

對於setTimeout()方法,指的是指定的毫秒數後執行指定的代碼或方法。

語法:window.setTimeout("javascript 函數",毫秒數);

實例1:3秒鍾後彈出」hello「提示框

setTimeout(function(){alert("Hello")},3000);

實例2:三秒鍾後跳轉到前一個頁面

<script type="text/javascript">
setTimeout(function(){
window.history.back();
},3000);
</script>
如何執行停止呢?

clearTimeout() 方法用於停止執行setTimeout()方法的函數代碼。這里注意myVar必須是一個全局變數。實例如下:

var myVar;
function myFunction()
{
myVar=setTimeout(function(){alert("Hello")},3000);
}

function myStopFunction()
{
clearTimeout(myVar);
}

以上就把js計時器的基本功能簡要介紹了,具體的使用場景,想要深刻理解,只有到項目用到時方可有新的理會。

❽ jquery或js前端提交數據的幾種方式

1.jquery提交數據的方式:
(1)第一種jquery序列化提交數據方式:
通過id獲取的form表單元素.serialize();
(2)第二種模擬form表單提交元素:
$('#form表單id').attr('method','post');
$('#form表單id'').find('input[name="type"]').val(test);
$('#form表單id').find('input[name="dfrom_to1"]').val(dfrom_to);
$('#form表單id').find('input[name="gt_road_new"]').val(gt_road);
$('#form表id').attr('action',AdminLTE.ctx+'/moles/ltegt/findAllCoverAndInterfere.do');
$('#analysisForm').submit();
2.js提交數據的方式:
(1).js提交表單( .submit()方法提交表單 )
function doSearch(){
var action ="<%=path%>/User_queryAllUser";
document.all.form.action = action;
document.all.form.submit();}
(2).js替代超鏈接( window.location.href )
<input type="button" id="modify" value="修改工號" οnclick="modifyEmp(${ myList.employeeId })">
//js不能起名為modify,為敏感關鍵字
function modifyEmp( employeeId ){
//employeeId 作為js的參數傳遞進來
window.location.href = '<%=path%>/User_openUserUpdate?employeeId='+employeeId;

❾ 用JS實現鍾表計時器功能

利用new Date();可以輕松的實現鍾表功能,甚至日歷功能.
如果要實現計時器功能也可以用這個對象.
var c = 1000; // 一千微秒,就是一秒

function funBeginDisTime() {
c = c + 1000; // 節奏為一秒
var now = new Date(0,0,0,0,0,0,c);
var day = now.getDate();
var hour = now.getHours();
var minutes = now.getMinutes();
var sec = now.getSeconds();

$("#myClock").html(day + "天"+ hour + "時" + minutes + "分" + sec + "秒");
myTime = setTimeout("funBeginDisTime()", 1000); // 每一秒執行一次
}

function funStopDisTime() {
clearTimeout(myTime);
}

body>
<input id="Button2" type="button" value="開始" onclick="funBeginDisTime()"/>
<span id="myClock"></span>
<input id="Button1" type="button" value="暫停" onclick="funStopDisTime()" />
</body>

setInterval() 是循環重復執行某個動作,

setTimeout()是只執行一次.
比如每五秒就通過AJAX向伺服器發送一次請求.那麼就可以用setInterval():

[javascript] view plain
setInterval("reloadAction()", 5000);
[javascript] view plain
function reloadAction() {
$.ajax({
"type":"POST",
"url":"live.php",
"data":"getData=live",
"success":function(data) {
// ....
}
});
}

❿ JS 倒計時實現代碼(時、分,秒)

JS實現倒計時(時、分,秒)
var
interval
=
1000;
function
ShowCountDown(year,month,day,divname)
{
var
now
=
new
Date();
var
endDate
=
new
Date(year,
month-1,
day);
var
leftTime=endDate.getTime()-now.getTime();
var
leftsecond
=
parseInt(leftTime/1000);
//var
day1=parseInt(leftsecond/(24*60*60*6));
var
day1=Math.floor(leftsecond/(60*60*24));
var
hour=Math.floor((leftsecond-day1*24*60*60)/3600);
var
minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);
var
second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
var
cc
=
document.getElementById(divname);
cc.innerHTML
=
"腳本之家提示距離"+year+"年"+month+"月"+day+"日還有:"+day1+"天"+hour+"小時"+minute+"分"+second+"秒";
}
window.setInterval(function(){ShowCountDown(2010,4,20,'divdown1');},
interval);
[Ctrl+A
全選
注:如需引入外部Js需刷新才能執行]

閱讀全文

與js計時提交數據相關的資料

熱點內容
手機怎麼在word製作作業文件 瀏覽:489
工行銀行卡安全升級 瀏覽:807
桌面放的文件找不到 瀏覽:922
買學生票用什麼app 瀏覽:590
共建共享網路平台 瀏覽:39
js傳值到超鏈接裡面 瀏覽:608
編程中的w和h是什麼 瀏覽:313
資料庫切了什麼意思 瀏覽:213
如何登錄極路由器設置密碼 瀏覽:522
jsp用戶登陸密碼加密源代碼 瀏覽:629
everfilter使用教程 瀏覽:768
作業票文件名稱是什麼 瀏覽:463
私密文件忘記密碼 瀏覽:686
藏文軟體app怎麼可以下載 瀏覽:960
鍵盤文件名 瀏覽:538
電腦自帶驅動在那個文件夾 瀏覽:531
c窗體讀取文件夾 瀏覽:965
asp婚紗攝影網站 瀏覽:684
文件恢復的原理 瀏覽:828
移動硬碟清空怎麼恢復數據 瀏覽:433

友情鏈接