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개
게시글 목록
| 번호 | 제목 |
|---|---|
| 11623 |
웹서버
FTP 프로세스 죽이기
1
|
| 20284 | |
| 291 | |
| 11622 | |
| 20283 |
CSS
CSS slider 테스트1
|
| 20282 |
CSS
수평메뉴1
|
| 11620 |
node.js
Node.js 서버의 기본적인 내용 정리
1
|
| 20281 |
기타
dpi 환산표(?)
|
| 11619 | |
| 20280 | |
| 11612 |
PHP
숫자를 한글로 변환
2
|
| 11611 | |
| 11608 |
PHP
썸네일 클래스입니다
2
|
| 11605 | |
| 11602 |
MySQL
자주쓰는 MYSQL
2
|
| 11601 | |
| 11600 |
PHP
두지점의 위도,경도간 거리계산
|
| 11599 | |
| 11597 |
MySQL
무한 로딩 중인 쿼리 죽이기
1
|
| 11596 |
기타
파폭 ssh, ftp
|
| 11595 |
MySQL
mysql 기본 사용법
|
| 11594 | |
| 11593 | |
| 11592 |
jQuery
제이쿼리를 이용하여 노드 선택
|
| 11591 |
jQuery
append를 이용하여 엘리먼트 추가하기
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기