1. 동적으로 HTML Form을 생성
<html>
<head>
</head>
<body>
<script>
generatorForm();
function generatorForm() {
var formEle = document.createElement("form");
formEle.setAttribute('method',"post");
formEle.setAttribute('action',"/action");
var tmpInput = document.createElement("input"); //input element, text
tmpInput.setAttribute('type',"text");
tmpInput.setAttribute('name',"tempValue");
formEle.appendChild(tmpInput);
var submitBtn = document.createElement("input"); //input element, Submit button
submitBtn.setAttribute('type',"submit");
submitBtn.setAttribute('value',"Submit BTN");
formEle.appendChild(submitBtn);
document.body.appendChild(formEle);
}
</script>
</body>
</html>
2. 문제 발생
1) 에러
document.body.appendChild(formEle);
- 위 소스를 추가 안할 경우 제대로 동작을 안함. 꼭 추가해야함.
'프로그래밍 > Javascript' 카테고리의 다른 글
How to detect browser. (0) | 2018.07.23 |
---|---|
Timer 구현하기 (0) | 2017.01.25 |