-1
如何將日誌保存到.txt?如何將日誌保存到.txt
<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 filePath = "/Users/ResetOfDirectoryPath/testWrite.txt";
function getCheckedValue(radioObj) {
if(!radioObj)
return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
if(radioObj.checked)
return radioObj.value;
else
return "";
for(var i = 0; i < radioLength; i++) {
if(radioObj[i].checked) {
return radioObj[i].value;
}
}
return "";
}
function uncheckedRadio() {
var radio_1 = document.clockform.gName;
var radio_2 = document.clockform.aName;
if(radio_1.length == undefined)
radio_1.checked = false;
else
for(var i = 0; i < radio_1.length; i++)
radio_1[i].checked = false;
if(radio_2.length == undefined)
radio_2.checked = false;
else
for(var i = 0; i < radio_2.length; i++)
radio_2[i].checked = false;
}
unction 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;
document.clockform.m0.value = '';
uncheckedRadio();
nrGola = 1;
}
var nrGola = 1;
function addMEM() {
if (init>0)
{
var mC = document.clockform.m0;
var gol = getCheckedValue(document.clockform.gName);
var asy = getCheckedValue(document.clockform.aName);
if(gol != '')
{
var mesOut = nrGola + " G: " + gol;
if(asy != '')
{
if(asy == gol)
{
alert('Error, asysta taki sam jak strzelca');
uncheckedRadio();
return false;
}
mesOut = mesOut + ", A: " + asy;
}
else
mesOut = mesOut + ", A: brak";
mesOut = mesOut + ", " + readout;
if(mC.value != '')
mC.value = mC.value + "\n" + mesOut;
else
mC.value = mesOut;
nrGola++;
uncheckedRadio();
}
else
alert('Nie wybrano strzelcy');
}
}
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 temp = document.clockform.m0.value;
if(temp != '')
{
uriContent = "data:text/plain;charset=utf-8," + encodeURIComponent(temp);
newWindow=window.open(uriContent, 'txt');
}
}
</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()"> <input name=marker type=button id ="dupa" value="Mark" style="width:84px" onclick="addMEM()"><br><font style="font-size:9pt"> </font></td>
</tr>
<tr><td>
<input type="radio" name="gName" value="1" /> 1<br>
<input type="radio" name="gName" value="2" /> 2<br>
<input type="radio" name="gName" value="3" /> 3<br>
<input type="radio" name="gName" value="4" /> 4<br>
<input type="radio" name="gName" value="5" /> 5<br>
<input type="radio" name="gName" value="6" /> 6<br>
</td>
<td>
<input type="radio" name="aName" value="1" /> 1<br>
<input type="radio" name="aName" value="2" /> 2<br>
<input type="radio" name="aName" value="3" /> 3<br>
<input type="radio" name="aName" value="4" /> 4<br>
<input type="radio" name="aName" value="5" /> 5<br>
<input type="radio" name="aName" 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>
你應該怎麼寫一個問題:http://stackoverflow.com/faq – oezi
我不認爲它是一個壞問題。 – Vish
他對社區來說是個新手,不應該受到積極的歡迎。想想所有來自谷歌的人到stackoverflow,並想知道這裏到底是什麼錯誤,現在當我想問一個問題時,我必須閱讀「如何做別的事情」。 – Vish