JavaScript備忘録

2007-04-16テーブルの連番をJavaScriptで表示する方法

<html>
<head>
<script language=javascript>
no = 1;
function showno() {
    document.write(no);
    no = no + 1;
}
</script>
</head>
<body>
<table border=1>
<tr>
    <td>No</td>
    <td>名前</td></tr>
<tr>
    <td><script language=javascript>showno()</script></td>
    <td>foo</td></tr>
<tr>
    <td><script language=javascript>showno()</script></td>
    <td>bar</td></tr>
<tr>
    <td><script language=javascript>showno()</script></td>
    <td>hoge</td></tr>
</table>

</body>
</html>