문의드립니다.
본문
아래의 소스는 밑에 이미지처럼 1행 추가를 클릭하면 입력 할 수 있는 행이 추가되는 소스입니다.
이걸 처음 부터 첫번째행이 보여지게 하고 1행 추가를 클릭하면 추가 행이 보이게 하려면 어떻게 해야 할까요?
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include (G5_THEME_PATH.'/skin/multi_category/lib.php');
if ($w == "u") {
$wr_body_1 = explode("|",substr($write[wr_1], 1));
$wr_body_2 = explode("|",substr($write[wr_2], 1));
}
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.css">', 0);
?>
<script>
function addRow() {
var oRow = dyntbl1.insertRow();
oRow.onmouseover=function(){dyntbl1.clickedRowIndex=this.rowIndex};
if(navigator.userAgent.indexOf("MSIE")){
var oCell1 = oRow.insertCell();
var oCell2 = oRow.insertCell();
var oCell6 = oRow.insertCell();
oCell1.innerHTML = "<input class='frm_input_a' required name=wr_body_1[] itemname='모델명' maxlength='100'>";
oCell2.innerHTML = "<input class='frm_input_b' name=wr_body_2[] itemname='제품시리얼번호' maxlength='100'>";
oCell6.innerHTML = "<input type=button style='width:60px;height:24px;' value=\" 삭제 \" onClick=\"delRow()\">";
document.recalc();
}
else if(navigator.userAgent.indexOf("Chrome")){
var oCell1 = oRow.insertCell();
var oCell2 = oRow.insertCell();
var oCell6 = oRow.insertCell();
oCell1.innerHTML = "<input class='frm_input_a' required name=wr_body_1[] itemname='모델명' maxlength='100'>";
oCell2.innerHTML = "<input class='frm_input_b' name=wr_body_2[] itemname='제품시리얼번호' maxlength='100'>";
oCell6.innerHTML = "<input type=button style='width:60px;height:24px;' value=\" 삭제 \" onClick=\"delRow()\">";
}
else if(navigator.userAgent.indexOf("Safari")){
var oCell6 = oRow.insertCell();
var oCell2 = oRow.insertCell();
var oCell1 = oRow.insertCell();
oCell6.innerHTML = "<input type=button style='width:60px;height:24px;' value=\" 삭제 \" onClick=\"delRow()\">";
oCell2.innerHTML = "<input class='frm_input_b' name=wr_body_2[] itemname='제품시리얼번호' maxlength='100'>";
oCell1.innerHTML = "<input class='frm_input_a' required name=wr_body_1[] itemname='모델명' maxlength='100'>";
}
else if(navigator.userAgent.indexOf("Firefox")){
var oCell6 = oRow.insertCell();
var oCell2 = oRow.insertCell();
var oCell1 = oRow.insertCell();
oCell6.innerHTML = "<input type=button style='width:60px;height:24px;' value=\" 삭제 \" onClick=\"delRow()\">";
oCell2.innerHTML = "<input class='frm_input_b' name=wr_body_2[] itemname='제품시리얼번호' maxlength='100'>";
oCell1.innerHTML = "<input class='frm_input_a' required name=wr_body_1[] itemname='모델명' maxlength='100'>";
}
}
function delRow() {
dyntbl1.deleteRow(dyntbl1.clickedRowIndex);
}
function delRow_php(r)
{
var i=r.parentNode.parentNode.rowIndex;
document.getElementById('dyntbl2').deleteRow(i);
}
function fixscreen() {
var buffer = document.all.item(0).outerHTML;
document.open("text/html", "replace");
document.write(buffer);
document.close();
}
function addCol() {
var vCell,tmp;
for (var i=0; i<dyntbl1.rows.length; i++) {
tmp=dyntbl1.rows[i].cells[dyntbl1.rows[i].cells.length-1].cloneNode(true);
dyntbl1.rows[i].deleteCell();
vCell=dyntbl1.rows[i].insertCell();
vCell.innerHTML=i==0?"<input type=button value=' X ' onclick='delCol(parentNode.cellIndex)'>":" ";
vCell=dyntbl1.rows[i].insertCell();
vCell.innerHTML=tmp.innerHTML;
}
}
function delCol(idx) {
for (var i=0; i<=dyntbl1.rows.length; i++) {
dyntbl1.rows[i].cells[idx].removeNode();
}
}
</script>
<!-- 요기 -->
<div id="1">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td colspan=2 height=40 align=center><input type=button style='width:90px;height:24px;' value="1행 추가 +" onClick="addRow()"></td></tr>
<tr>
<td colspan="2">
<table width="100%" cellspacing=1 cellpadding=3 bgcolor="#CCCCCC">
<col width="30%"></col>
<col width="60%"></col>
<col width="10%"></col>
<tr height="30">
<td class=write_cb><b>모델명 </b></td>
<td class=write_cb><b>제품시리얼번호</b></td>
<td class=write_cb><b>삭제</b></td>
</tr>
</table>
<? if ($w == "u") { ?>
<table id=dyntbl2 width="100%" cellspacing=1 cellpadding=3 bgcolor="#CCCCCC">
<col bgcolor="#FFFFFF" align="center" width="30%"></col>
<col bgcolor="#FFFFFF" align="center" width="60%"></col>
<col bgcolor="#FFFFFF" align="center" width="10%"></col>
<div>
<? for ($i = 0; $i < count($wr_body_1); $i++) { ?>
<tr height="30" id=v_<?=$i?>>
<td><input class='frm_input_a' name=wr_body_1[] itemname='모델명' value='<?=$wr_body_1[$i]?>' maxlength='40'></td>
<td>
<input class='frm_input_b' name=wr_body_2[] itemname='제품시리얼번호' value='<?=$wr_body_2[$i]?>' maxlength='160' >
</td>
<td><input type=button value=" 삭제 " onClick="delRow_php(this)"></td>
</tr>
<? } ?>
</div>
</table>
<? } ?>
<table id=dyntbl1 width="100%" cellspacing=1 cellpadding=3 bgcolor="#EEEEEE">
<col bgcolor="#FFFFFF" align="center" width="30%"></col>
<col bgcolor="#FFFFFF" align="center" width="60%"></col>
<col bgcolor="#FFFFFF" align="center" width="10%"></col>
</table>
</td>
</tr></table>
</div>
<!-- 까지 -->