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개
게시글 목록
| 번호 | 제목 |
|---|---|
| 11800 |
jQuery
마우스 오버 위치에 따라 툴팁 생성 및 자동 이동
|
| 11798 | |
| 11797 |
jQuery
제이쿼리 동적으로 생성된 객체에 이벤트 생성하기
|
| 11796 | |
| 11795 | |
| 11794 |
JavaScript
shuffle 배열섞기
|
| 11793 |
jQuery
제이쿼리 모음 사이트
|
| 11792 |
PHP
1원팁] IP 대역 비교
|
| 11791 | |
| 20314 | |
| 11785 |
PHP
input 쉽게 관리하기
5
|
| 11782 |
JavaScript
서버시간을 사용한 전자시계
2
|
| 11781 | |
| 20312 | |
| 11780 |
JavaScript
구글 웹사이트 번역기를 내 사이트에 달기
|
| 11778 | |
| 11773 | |
| 293 | |
| 11772 |
JavaScript
자바스크립트(4)
|
| 11771 |
PHP
자바스크립트(3)
|
| 11770 |
JavaScript
자바스크립트(2)
|
| 11769 |
JavaScript
자바스크립트(1)
|
| 11767 |
PHP
정규 표현식
1
|
| 11766 |
PHP
기타 함수
|
| 11765 |
PHP
수학 연산 함수
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기