Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- htmlFor
- Openlayers
- VAR
- const
- Append
- 학습법 #집중력
- FOR
- boolean
- createElement
- createtextnode
- input
- Let
- appendChild
Archives
- Today
- Total
Atomic Habits
form, input 동적 생성 및 submit 본문
/* Javascript */
// create element (form)
var newForm = document.createElement('form');
// set attribute (form)
newForm.name = 'newForm';
newForm.method = 'post';
newForm.action = 'https://ifuwanna.tistory.com/196';
newForm.target = '_blank';
// create element (input)
var input1 = document.createElement('input');
var input2 = document.createElement('input');
// set attribute (input)
input1.setAttribute("type", "hidden");
input1.setAttribute("name", "data1");
input1.setAttribute("value", "value1");
input2.setAttribute("type", "hidden");
input2.setAttribute("name", "data2");
input2.setAttribute("value", "value2");
// append input (to form)
newForm.appendChild(input1);
newForm.appendChild(input2);
// append form (to body)
document.body.appendChild(newForm);
// submit form
newForm.submit();
/* JQUERY */
//create element (form)
var newForm = $('<form></form>');
//set attribute (form)
newForm.attr("name","newForm");
newForm.attr("method","post");
newForm.attr("action","https://ifuwanna.tistory.com/196");
newForm.attr("target","_blank");
// create element & set attribute (input)
newForm.append($('<input/>', {type: 'hidden', name: 'data1', value:'value1' }));
newForm.append($('<input/>', {type: 'hidden', name: 'data2', value:'value2' }));
// append form (to body)
newForm.appendTo('body');
// submit form
newForm.submit();
'IT > JavaScript-JQuery' 카테고리의 다른 글
[javascript] setTimeout, setInterval, clearInterval (0) | 2021.10.17 |
---|---|
[JavaScript] var, let, const (0) | 2021.09.16 |
[JavaScript] 참 같은 값(truthy value) (0) | 2021.09.11 |
[JavaScript] .createElement(), .createTextNode(), .appendChild() (0) | 2021.09.01 |
[HTML] HTML labal for 속성 (0) | 2021.09.01 |
Comments