html 테이블을 만들었습니다. 버튼을 통해 테이블에 더 많은 행을 동적으로 추가 할 수 있습니다. 문제는 3 개의 텍스트 상자와 하나의 입력 유형 번호 (입력 유형 번호는 셀 3에 속해야 함)를 추가하는 방법을 모르겠다는 것입니다. 이것은 내 기능입니다.
function Add()
{
var tableRef = document.getElementById('tabella').getElementsByTagName('tbody')[0];
// Insert a row in the table at the last row
var newRow = tableRef.insertRow(tableRef.rows.length);
// Insert a cell in the row at index 0
var newCell = newRow.insertCell(0);
var newCell1 = newRow.insertCell(1);
var newCell2 = newRow.insertCell(2);
var newCell3 = newRow.insertCell(3);
// Append a text node to the cell
var newText = document.createTextNode('New row')
newCell.appendChild(newText);
}
질문을 올바르게 이해했으면합니다. 이 코드를 Add 함수 안에 넣으십시오 .
var input = document.createElement('input'),
input1 = document.createElement('input'),
input2 = document.createElement('input'),
input3 = document.createElement('input');
input.type = 'text';
input1.type = 'text';
input2.type = 'text';
input3.type = 'number';
newCell.appendChild(input);
newCell1.appendChild(input1);
newCell2.appendChild(input2);
newCell3.appendChild(input3);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다