ユーザーの詳細を受け入れるhtmlフォームがあります.htmlフォームデータをテーブルに表示したいです。では、Javascript でこれを実現するにはどうすればよいでしょうか。
質問する
2367 次
2 に答える
0
サーバー側の投稿を使用していないように聞こえますが、フォームに情報を入力して同じページの表に表示しようとしているだけです。私は正しいですか?
その場合、これは使用できる関数の例です。
JavaScript:
function addRowToTable() {
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
// left cell
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
cellLeft.appendChild(textNode);
// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.type = 'text';
el.name = 'txtRow' + iteration;
el.id = 'txtRow' + iteration;
el.size = 40;
cellRight.appendChild(el);
}
function removeRowFromTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}
完全な実装については、次のリンクをたどってください: http://www.codeproject.com/Articles/19532/Dynamic-Table-using-html-and-javascript
于 2013-06-13T09:50:37.003 に答える