insertRow,insertCell,createElement,innerHTML 을 사용하시면 됩니다.
예제입니다.
<html>
<head>
<script>
function myAdd() {
var tab=document.all.mytable;
var row=tab.insertRow();
var col=row.insertCell();
var inp=document.createElement("input");
inp.type="text";
col.innerHTML=inp.outerHTML;
}
</script>
</head>
<body>
<input type=button value=add onclick=myAdd()>
<table id=mytable border=1></table>
</body>
</html>
답변 내용 추가
맞습니다.
inp.name="test";
형태로 하시면 됩니다.
name이 같게 여러개를 주면 배열로 보시고 null확인 등의 작업을 하시면 됩니다.
예)
if (typeof(document.formname.test.length)=="undefined") {
if (document.formname.test.value=="") {
alert("test값이 null입니다");
document.formname.test.focus();
}
} else {
for (var i=0; i<document.formname.test.length; i++) {
if (document.formname.test[i].value=="") {
alert((i+1)+"번째 test값이 null입니다");
document.formname.test[i].focus();
break; //혹은 함수면 return;
}
}
}
혹은 애초에 name속성에 일련번호등을 붙여 값을 다르게 주는 방법도 있겠습니다.<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
예제입니다.
<html>
<head>
<script>
function myAdd() {
var tab=document.all.mytable;
var row=tab.insertRow();
var col=row.insertCell();
var inp=document.createElement("input");
inp.type="text";
col.innerHTML=inp.outerHTML;
}
</script>
</head>
<body>
<input type=button value=add onclick=myAdd()>
<table id=mytable border=1></table>
</body>
</html>
답변 내용 추가
맞습니다.
inp.name="test";
형태로 하시면 됩니다.
name이 같게 여러개를 주면 배열로 보시고 null확인 등의 작업을 하시면 됩니다.
예)
if (typeof(document.formname.test.length)=="undefined") {
if (document.formname.test.value=="") {
alert("test값이 null입니다");
document.formname.test.focus();
}
} else {
for (var i=0; i<document.formname.test.length; i++) {
if (document.formname.test[i].value=="") {
alert((i+1)+"번째 test값이 null입니다");
document.formname.test[i].focus();
break; //혹은 함수면 return;
}
}
}
혹은 애초에 name속성에 일련번호등을 붙여 값을 다르게 주는 방법도 있겠습니다.<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
댓글 2개
19년 전
오!
19년 전
주제랑은 좀 틀린거 같은데.... ㅡㅡ^
name 값을 'test[]' 주고
document.getElementsByName('test[]') 로 접근하시길 권장한다고 하네요..? 누가? 음.......
ex)
var str_var = document.getElementsByName('test[]');
for(i=0;i<str_var.length;i++) {
alert(str_var[i].value);
}
name 값을 'test[]' 주고
document.getElementsByName('test[]') 로 접근하시길 권장한다고 하네요..? 누가? 음.......
ex)
var str_var = document.getElementsByName('test[]');
for(i=0;i<str_var.length;i++) {
alert(str_var[i].value);
}
게시판 목록
팁게시판
디자인과 관련된 유용한 정보를 공유하세요.
질문은 상단의 QA에서 해주시기 바랍니다.
질문은 상단의 QA에서 해주시기 바랍니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5577 |
잘살아보자
|
11년 전 | 955 | |
| 5576 | 11년 전 | 1011 | ||
| 5575 |
잘살아보자
|
11년 전 | 1083 | |
| 5574 | 11년 전 | 808 | ||
| 5573 |
잘살아보자
|
11년 전 | 1839 | |
| 5572 |
잘살아보자
|
11년 전 | 3011 | |
| 5571 |
잘살아보자
|
11년 전 | 985 | |
| 5570 |
잘살아보자
|
11년 전 | 758 | |
| 5569 |
잘살아보자
|
11년 전 | 2695 | |
| 5568 | 11년 전 | 953 | ||
| 5567 | 11년 전 | 1413 | ||
| 5566 | 11년 전 | 825 | ||
| 5565 | 11년 전 | 1476 | ||
| 5564 |
잘살아보자
|
11년 전 | 1016 | |
| 5563 |
잘살아보자
|
11년 전 | 658 | |
| 5562 |
잘살아보자
|
11년 전 | 1259 | |
| 5561 |
잘살아보자
|
11년 전 | 1241 | |
| 5560 | 11년 전 | 902 | ||
| 5559 | 11년 전 | 1902 | ||
| 5558 | 11년 전 | 663 | ||
| 5557 | 11년 전 | 1076 | ||
| 5556 | 11년 전 | 1299 | ||
| 5555 | 11년 전 | 837 | ||
| 5554 | 11년 전 | 796 | ||
| 5553 | 11년 전 | 854 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기