테이블에 새 행을 추가하는 JavaScript 함수가 있습니다. 입력 (텍스트), 텍스트 상자 및 라디오와 같은 데이터 유형을 절대적으로 잘 추가하여 작동합니다. 그것은 또한 사용하여 작동기존 테이블에 작동 선택 요소 추가
document.createElement ('select');
하지만 요소 추가를 시도하자마자 JS 함수를 트리거하는 버튼은 아무 것도하지 않습니다. 이는 오류가 있음을 의미한다고 생각하지만 문제가 무엇인지 표시하지 않습니다. 나는 방금 단순한 것을 놓쳤다라고 확신한다. 그러나 그것은 나를 몇 시간 동안 뒤로 붙들고 있었다. 그리고 그것은 나를 미치게했다!
다른 모든 데이터 형식이 자체적으로 테이블 셀을 만들고 추가하기 때문에 함수 본체가 문제가 없습니다. 제대로 함수 내에서 작동 JS의 예 :
// inner left cell - text input
var cellTwo = row.insertCell(1);
var el = document.createElement('input');
el.type = 'text';
el.name = 'col' + rowNumber;
el.id = 'col' + rowNumber;
cellTwo.appendChild(el);
시도하고 옵션을 작업과 선택 요소를 생성하는 코드를 : (내가 옵션 부분을 주석 단순히 빈 선택 요소를 만드는 경우이 작품 NB, 그래서 오류가 FOOR 루프 내 어딘가에 있어야한다 그냥 동적 옵션을 만드는 방법 나의 오해의 결과이어야합니다.
가 어떤 도움이 많이 주시면 감사하겠습니다// inner right cell - select box
var cellThree = row.insertCell(2);
//create select element
var dropDown = document.createElement('select');
//give select element id and name
dropDown.id = 'fieldtypecol' + rowNumber;
dropDown.name = 'fieldtypecol' + rowNumber;
//declare array values to put in option elements
var optionValue[] = new Array('varchar(255)', 'int', 'date', 'float(53)');
var optionText[] = new Array('String', 'Integer', 'Date', 'Float');
//declare option element holder
var option;
//loop through creating and adding values to options
for (var i = 0; i < 4; i++)
{
option = document.createElement('option');
option.value = optionValue[i];
option.text = optionText[i];
//append current option before loop restarts
dropDown.appendChild(option);
}
//append select element to new table cell
cellThree.appendChild(dropDown);
, 감사
optionValue []'은 구문 오류이므로 javascript의 선언에 변수 이름 뒤에'[]'를 넣지 마십시오. 자바 스크립트 콘솔에서 구문 및 유사한 오류를 확인하십시오. –