그래서 나는 다음과 같은 HTML을 가지고 : 자바 스크립트를 만든 라벨이 잘못된 위치에 삽입
<div id="divForComponents">
<input type="button" value="+" onclick="addFilter('divForComponents')"/>
</div>
그리고 내 스크립트 파일에서
:function addFilter(divId){
var div = document.getElementById(divId);
var label = document.createElement("label");
var text = document.createTextNode("Filter by:");
label.appendChild(text);
div.appendChild(label);
var filter = document.createElement("select");
filter.name = "selectName";
filter.options[0] = new Option("selection 1","value 1");
filter.options[1] = new Option("selection 2","value 2");
filter.options[2] = new Option("selection 3","value 3");
filter.options[3] = new Option("selection 4","value 4");
div.appendChild(filter);
var input = document.createElement("input");
input.type = "text";
input.name = "inputName";
div.appendChild(input);
}
지금 구성 요소 선택 및 입력 필드가 제대로 추가되지만 이미 해당 div에 있던 단추 앞에 레이블이 추가됩니다. 내가 좋아하고 위치를 얻기 위해 기대 :
Button Label Select Input
대신 내가 얻을 :
Label Button Select Input
I가 테스트하고있어 브라우저가 여기에 아무것도 계산 확실하지 크롬입니다.
감사합니다, 보그
난 당신의 코드에서 버튼이 표시되지 않습니다. –
버튼이 이미 div에 있습니다. – Bogdan