<!DOCTYPE html>
<html lang="ru">
<SCRIPT TYPE="text/javascript">
function onkeydown_event(e)
{
if (e.keyCode == 32) // space
but_onclick(document.getElementsByName ("but1")[0]);
if (e.keyCode == 37) // left
but_onclick(document.getElementsByName ("but2")[0]);
if (e.keyCode == 40) // down
but_onclick(document.getElementsByName ("but3")[0]);
if (e.keyCode == 39) // right
but_onclick(document.getElementsByName ("but4")[0]);
if (e.keyCode == 38) // up
but_onclick(document.getElementsByName ("but5")[0]);
if (e.keyCode == 16) // shift
but_onclick(document.getElementsByName ("but6")[0]);
// Прочие кнопки:
// http://www.asquare.net/javascript/tests/KeyCode.html
}
function but_onclick(o)
{
Add_Tab_TR(o);
}
function Add_Tab_TR(o)
{
o.focus();
dt = new Date();
h = dt.getHours();
m= dt.getMinutes();
s= dt.getSeconds();
ms= dt.getMilliseconds();
rows_l = document.all.tab1.rows.length;
NewRow = document.all.tab1.insertRow(rows_l);
butName = o.name;
butNum = butName.substr(3);
inpName ="inp" + butNum;
inpObj = document.getElementsByName (inpName);
if (inpObj != undefined)
evName = inpObj[0].value;
else
evName = inpObj[0].name;
NewCell = NewRow.insertCell(0); NewCell.innerHTML=h;
NewCell = NewRow.insertCell(1); NewCell.innerHTML=m;
NewCell = NewRow.insertCell(2); NewCell.innerHTML=s;
NewCell = NewRow.insertCell(3); NewCell.innerHTML=ms;
NewCell = NewRow.insertCell(4); NewCell.innerHTML=evName;
//**** Суммы:
// по кнопке:
butRow = document.all.tabBut.rows[butNum-1];
contCell = butRow.cells[1];
celValue = contCell.innerHTML.trim();
if (celValue.length== 0)
contCell.innerHTML = 1;
else
contCell.innerHTML = eval(celValue)+1;
// Считать итог:
intSum = 0;
for( i = 0;i<document.all.tabBut.rows.length-1;i++)
{
butRow = document.all.tabBut.rows[i];
contCell = butRow.cells[1];
celValue = contCell.innerHTML.trim();
if (celValue.length== 0)
celValue = 0;
intSum = intSum + eval(celValue);
}
// Записать итог:
butRow = document.all.tabBut.rows[document.all.tabBut.rows.length-1];
contCell = butRow.cells[1];
contCell.innerHTML = intSum;
}
</SCRIPT>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=cp1251">
<title>Счетчик</title>
</head>
<body onkeydown="onkeydown_event(event);">
<table id="tabBut" name ="tabBut" border="1">
<tr>
<td>
<input name="but1" id = "but1" type="button" onclick="but_onclick(this)" value="1" />
<input name="inp1" id = "inp1" type="text" value="Start" size="20" style="width:150px;"/>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input name="but2" id = "but2" type="button" onclick="but_onclick(this)" value="2"/>
<input name="inp2" id = "inp2" type="text" value="Медлено" size="20" style="width:150px;"/>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input name="but3" id = "but3" type="button" onclick="but_onclick(this)" value="3"/>
<input name="inp3" id = "inp3" type="text" value="Средне" size="20" style="width:150px;"/>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input name="but4" id = "but4" type="button" onclick="but_onclick(this)" value="4"/>
<input name="inp4" id = "inp4" type="text" value="Быстро" size="20" style="width:150px;"/>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input name="but5" id = "but5" type="button" onclick="but_onclick(this)" value="5"/>
<input name="inp5" id = "inp5" type="text" value="Очень быстро" size="20" style="width:150px;"/>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input name="but6" id = "but6" type="button" onclick="but_onclick(this)" value="6"/>
<input name="inp6" id = "inp6" type="text" value="Stop" size="20" style="width:150px;"/>
</td>
<td>
</td>
</tr>
<tr>
<td>Итого:</td>
<td></td>
</tr>
</table>
<table id="tab1" name="tab1" border="1">
<tr><td>Час</td><td>Мин</td><td>с</td><td>мс</td><td>Событие</td></tr>
</table>
</body>
</html>
|