2011-07-19 43 views
0

我需要js從定時器下一個讀取值從單選按鈕,並在msgbox像「00:08:30:12,1,4」節省時間和價值。我有一個計時器和一段js代碼,但是Idk現在要做什麼。有誰能夠幫助我 ?Java腳本geet時間和值從單選按鈕

<html> 
<head> 
<title>Javascript Stopwatch</title> 
<script language="javascript"> 

var base = 60; 

var clocktimer,dateObj,dh,dm,ds,ms; 
var readout=''; 
var h=1; 
var m=1; 
var tm=1; 
var s=0; 
var ts=0; 
var ms=0; 
var show=true; 
var init=0; 
var m0=0; 
var mPLUS=new Array(
    'm0', 
    'm1', 
    'm2', 
    'm3', 
    'm4', 
    'm5', 
    'm6', 
    'm7', 
    'm8', 
    'm9' 
    ); 
var ii=0; 

function clearALL() { 
    clearTimeout(clocktimer); 
    h=1;m=1;tm=1;s=0;ts=0;ms=0; 
    init=0;show=true; 
    readout='00:00:00.00'; 
    document.clockform.clock.value=readout; 
    var CF = document.clockform; 
    for (ij=0;ij<=9;ij++) { CF[mPLUS[ij]].value = ''; } 
    ii = 0; 
    } 

function addMEM() { 
if (init>0) { 
     var CF = document.clockform; 
     CF[mPLUS[ii]].value = readout; 
     if (ii==9) { ii = 0; } else { ii++; } 
     } 
} 


function startTIME() { 

var cdateObj = new Date(); 
var t = (cdateObj.getTime() - dateObj.getTime())-(s*1000); 

if (t>999) { s++; } 

if (s>=(m*base)) { 
    ts=0; 
    m++; 
    } else { 
    ts=parseInt((ms/100)+s); 
    if(ts>=base) { ts=ts-((m-1)*base); } 
    } 

if (m>(h*base)) { 
    tm=1; 
    h++; 
    } else { 
    tm=parseInt((ms/100)+m); 
    if(tm>=base) { tm=tm-((h-1)*base); } 
    } 

ms = Math.round(t/10); 
if (ms>99) {ms=0;} 
if (ms==0) {ms='00';} 
if (ms>0&&ms<=9) { ms = '0'+ms; } 

if (ts>0) { ds = ts; if (ts<10) { ds = '0'+ts; }} else { ds = '00'; } 
dm=tm-1; 
if (dm>0) { if (dm<10) { dm = '0'+dm; }} else { dm = '00'; } 
dh=h-1; 
if (dh>0) { if (dh<10) { dh = '0'+dh; }} else { dh = '00'; } 

readout = dh + ':' + dm + ':' + ds + '.' + ms; 
if (show==true) { document.clockform.clock.value = readout; } 

clocktimer = setTimeout("startTIME()",1); 
} 

function findTIME() { 
if (init==0) { 
    dateObj = new Date(); 
    startTIME(); 
    init=1; 
    } 

} 
</script> 
</head> 
<body bgcolor=tan> 
<form name=clockform> 
<table bgcolor=cornsilk align=center cellpadding=5 border=1 bordercolor=burlywood><tr><td> 
<table cellpadding=3 cellspacing=0 border=0 align=center> 
<tr> 
<td bgcolor=wheat><input name=clock value="00:00:00.00" style="text-align:center; width:174px; height:35px; font-size:24; font-weight:bold"></td> 
<td valign=top bgcolor=wheat><input name=clearer type=button value="Reset" onclick="clearALL()"></td> 
</tr> 
<tr> 
<td colspan=2 bgcolor=wheat> 
<input name=starter type=button value="Start" style="width:97px; font-weight:bold" onclick="findTIME()">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<input name=marker type=button value="Mark" style="width:84px" onclick="addMEM()"><br><font style="font-size:9pt">&nbsp;</font></td> 
</tr> 

</table> 
<table cellpadding=3 cellspacing=0 border=0 align=left> 
<div align="left"><br> 
<input type="radio" name="group1" value="1"> 1<br> 
<input type="radio" name="group1" value="2"> 2<br> 
<input type="radio" name="group1" value="3"> 3<br> 
<input type="radio" name="group1" value="4"> 4<br> 
<input type="radio" name="group1" value="5"> 5<br> 
<input type="radio" name="group1" value="6"> 6<br> 
</div> 
<div align="right"><br> 
<input type="radio" name="group2" value="1"> 1<br> 
<input type="radio" name="group2" value="2"> 2<br> 
<input type="radio" name="group2" value="3"> 3<br> 
<input type="radio" name="group2" value="4"> 4<br> 
<input type="radio" name="group2" value="5"> 5<br> 
<input type="radio" name="group2" value="6"> 6<br> 
</div> 
</table> 
<table cellpadding=3 cellspacing=0 border=0 align=center style="width:97px; font-weight:bold"> 
<textarea name="m0" style="text-align:left; width:83px cols="40" rows="5" readonly="readonly"> 
</textarea> 
</form> 
</table> 

</body> 
</html> 
+0

一些代碼 「00:08:30:12,1,4」 做ü平均值1,4是來自收音機的值? – Sarath

+1

偏離主題,但很重要:您的頁面佈局使用了一些非常令人討厭的表格結構。你也沒有得到一個文檔類型。你的風格還有一些過時的方面。你需要更新你的編碼技術。 – Spudley

回答

0

這裏是你

我也是固定復位,並在該表的某些問題

<html> 
<head> 
<title>Javascript Stopwatch</title> 
<script language="javascript"> 

var base = 60; 

var clocktimer,dateObj,dh,dm,ds,ms; 
var readout=''; 
var h=1; 
var m=1; 
var tm=1; 
var s=0; 
var ts=0; 
var ms=0; 
var show=true; 
var init=0; 
var m0=0; 
var mPLUS=['m0','m1','m2','m3','m4','m5','m6','m7','m8','m9']; 
var ii=0; 

function clearALL() { 
    clearTimeout(clocktimer); 
    h=1;m=1;tm=1;s=0;ts=0;ms=0; 
    init=0;show=true; 
    readout='00:00:00.00'; 
    document.clockform.clock.value=readout; 
    var CF = document.clockform; 
    for (ij=0;ij<mPLUS.length;ij++) { if (CF[mPLUS[ij]]) CF[mPLUS[ij]].value = ''; } 
    ii = 0; 
    } 

function addMEM() { 
if (init>0) { 
     var CF = document.clockform; 
     CF[mPLUS[ii]].value = readout; 
     if (ii==9) { ii = 0; } else { ii++; } 
     } 
} 


function startTIME() { 

var cdateObj = new Date(); 
var t = (cdateObj.getTime() - dateObj.getTime())-(s*1000); 

if (t>999) { s++; } 

if (s>=(m*base)) { 
    ts=0; 
    m++; 
    } else { 
    ts=parseInt((ms/100)+s); 
    if(ts>=base) { ts=ts-((m-1)*base); } 
    } 

if (m>(h*base)) { 
    tm=1; 
    h++; 
    } else { 
    tm=parseInt((ms/100)+m); 
    if(tm>=base) { tm=tm-((h-1)*base); } 
    } 

ms = Math.round(t/10); 
if (ms>99) {ms=0;} 
if (ms==0) {ms='00';} 
if (ms>0&&ms<=9) { ms = '0'+ms; } 

if (ts>0) { ds = ts; if (ts<10) { ds = '0'+ts; }} else { ds = '00'; } 
dm=tm-1; 
if (dm>0) { if (dm<10) { dm = '0'+dm; }} else { dm = '00'; } 
dh=h-1; 
if (dh>0) { if (dh<10) { dh = '0'+dh; }} else { dh = '00'; } 

readout = dh + ':' + dm + ':' + ds + '.' + ms; 
if (show==true) { document.clockform.clock.value = readout; } 

clocktimer = setTimeout("startTIME()",1); 
} 

function findTIME() { 
if (init==0) { 
    dateObj = new Date(); 
    startTIME(); 
    init=1; 
    } 
} 
var times = {}; 
window.onload=function() { 
    var inpt = document.getElementsByTagName("input"); 
    for (var i=0,n=inpt.length;i<n;i++) { 
    if (inpt[i].type=="radio") inpt[i].onclick=function() { 
     times[this.id]=this.form.m0.value=this.form.clock.value; 
    } 
    } 
} 
function showTimes() { 
    var text =""; 
    for (var o in times) text += o+":"+times[o]+"\n" 
    if (text) alert(text) 
} 

</script> 
</head> 
<body bgcolor=tan> 
<form name=clockform> 
<table bgcolor=cornsilk align=center cellpadding=5 border=1 bordercolor=burlywood><tr><td> 
<table cellpadding=3 cellspacing=0 border=0 align=center> 
<tr> 
<td bgcolor=wheat><input name=clock value="00:00:00.00" style="text-align:center; width:174px; height:35px; font-size:24; font-weight:bold"></td> 
<td valign=top bgcolor=wheat><input name=clearer type=button value="Reset" onclick="clearALL()"></td> 
</tr> 
<tr> 
<td colspan=2 bgcolor=wheat> 
<input name=starter type=button value="Start" style="width:97px; font-weight:bold" onclick="findTIME()">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<input name=marker type=button value="Mark" style="width:84px" onclick="addMEM()"><br><font style="font-size:9pt">&nbsp;</font></td> 
</tr> 

<tr><td> 
<input type="radio" name="group1" id="r1.1" value="1"> 1<br> 
<input type="radio" name="group1" id="r1.2" value="2"> 2<br> 
<input type="radio" name="group1" id="r1.3" value="3"> 3<br> 
<input type="radio" name="group1" id="r1.4" value="4"> 4<br> 
<input type="radio" name="group1" id="r1.5" value="5"> 5<br> 
<input type="radio" name="group1" id="r1.6" value="6"> 6<br> 
</td> 
<td> 
<input type="radio" name="group2" id="r2.1" value="1"> 1<br> 
<input type="radio" name="group2" id="r2.2" value="2"> 2<br> 
<input type="radio" name="group2" id="r2.3" value="3"> 3<br> 
<input type="radio" name="group2" id="r2.4" value="4"> 4<br> 
<input type="radio" name="group2" id="r2.5" value="5"> 5<br> 
<input type="radio" name="group2" id="r2.6" value="6"> 6<br> 
</td> 
</tr> 
<tr><td colspan="2"> 
<textarea name="m0" style="text-align:left; width:83px cols="40" rows="5" readonly="readonly"> 
</textarea> 
<input type="button" onclick="showTimes()" value="show times"> 
</td> 
</tr> 
</table> 
</form> 


</body> 
</html> 
+0

我做電子禮物。訪問我的[網站](http://plungjan.name/) – mplungjan