想要的效果是这个样子的
帝国多值字段是
输入表单替换html代码
<script>
function domvadd_more1()
{
var i;
var str='';
var oldi=0;
var j=0;
var addnum=0;
addnum=parseInt(document.add.mvaddnum_more1.value);
oldi=parseInt(document.add.mveditnum_more1.value);
for(i=1;i<=addnum;i++)
{
j=i+oldi;
str=str+'<tr><td align="center"><input type="text" name="more1_1[]" id="more1_1_'+j+'" value=""></td><td align="center"><input type="text" name="more1_2[]" id="more1_2_'+j+'" value=""></td><td align="center"><input type="text" name="more1_3[]" id="more1_3_'+j+'" value=""></td><td align="center"><input type="text" name="more1_4[]" id="more1_4_'+j+'" value=""></td><td align="center"><input type="text" name="more1_5[]" id="more1_5_'+j+'" value=""></td><td align="center"><input type="text" name="more1_6[]" id="more1_6_'+j+'" value=""></td></tr>';
}
document.getElementById("mvadd_more1").innerHTML="<table width='100%' border=0 cellspacing=1 cellpadding=3>"+str+"</table>";
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#DBEAF5">
<tr><td align="center">设置1</td><td align="center">设置2</td><td align="center">设置3</td><td align="center">设置4</td><td align="center">设置5</td><td align="center">设置6</td></tr>
</table>
</td>
</tr>
<tr>
<td>
<?php
if($ecmsfirstpost==1)
{
?>
<table width='100%' border=0 cellspacing=1 cellpadding=3>
<?php
$editnum=2;
for($i=1;$i<=$editnum;$i++)
{
?>
<tr><td align="center"><input type="text" name="more1_1[]" id="more1_1_<?=$i?>" value=""></td><td align="center"><input type="text" name="more1_2[]" id="more1_2_<?=$i?>" value=""></td><td align="center"><input type="text" name="more1_3[]" id="more1_3_<?=$i?>" value=""></td><td align="center"><input type="text" name="more1_4[]" id="more1_4_<?=$i?>" value=""></td><td align="center"><input type="text" name="more1_5[]" id="more1_5_<?=$i?>" value=""></td><td align="center"><input type="text" name="more1_6[]" id="more1_6_<?=$i?>" value=""></td></tr>
<?php
}
?>
</table>
<?php
}
else
{
$editnum=0;
if($r['more1'])
{
$r['more1']=stripSlashes($r['more1']);
?>
<table width='100%' border=0 cellspacing=1 cellpadding=3>
<?php
//录入项
$j=0;
$mvf_record=explode('||||||',$r['more1']);
$mvf_count=count($mvf_record);
for($i=0;$i<$mvf_count;$i++)
{
$j=$i+1;
$mvf_field=explode("::::::",$mvf_record[$i]);
?>
<tr><td align="center"><input type="text" name="more1_1[]" id="more1_1_<?=$j?>" value="<?=$mvf_field[0]?>"> <input type="hidden" name="more1_mvid[]" id="more1_mvid_<?=$j?>" value="<?=$j?>"><input type="checkbox" name="more1_mvdelid[]" id="more1_mvdelid_<?=$j?>" value="<?=$j?>">删</td><td align="center"><input type="text" name="more1_2[]" id="more1_2_<?=$j?>" value="<?=$mvf_field[1]?>"></td><td align="center"><input type="text" name="more1_3[]" id="more1_3_<?=$j?>" value="<?=$mvf_field[2]?>"></td><td align="center"><input type="text" name="more1_4[]" id="more1_4_<?=$j?>" value="<?=$mvf_field[3]?>"></td><td align="center"><input type="text" name="more1_5[]" id="more1_5_<?=$j?>" value="<?=$mvf_field[4]?>"></td><td align="center"><input type="text" name="more1_6[]" id="more1_6_<?=$j?>" value="<?=$mvf_field[5]?>"></td></tr>
<?php
}
?>
</table>
<?php
$editnum=$j;
}
}
?>
</td>
</tr>
<tr>
<td height="25">扩展数量: <input name="mveditnum_more1" type="hidden" id="mveditnum_more1" value="<?=$editnum?>">
<input name="mvnum_more1" type="hidden" id="mvnum_more1" value="6">
<input name="mvmust_more1" type="hidden" id="mvmust_more1" value="1">
<input name="mvaddnum_more1" type="text" id="mvaddnum_more1" value="1" size="6"> <input type="button" name="Submit5" value="输出" οnclick="javascript:domvadd_more1();"></td>
</tr>
<tr>
<td id="mvadd_more1"></td>
</tr>
</table>
投稿表单替换html代码
<script>
function domvadd_more1()
{
var i;
var str='';
var oldi=0;
var j=0;
var addnum=0;
addnum=parseInt(document.add.mvaddnum_more1.value);
oldi=parseInt(document.add.mveditnum_more1.value);
for(i=1;i<=addnum;i++)
{
j=i+oldi;
str=str+'<tr><td align="center"><input type="text" name="more1_1[]" id="more1_1_'+j+'" value=""></td><td align="center"><input type="text" name="more1_2[]" id="more1_2_'+j+'" value=""></td><td align="center"><input type="text" name="more1_3[]" id="more1_3_'+j+'" value=""></td><td align="center"><input type="text" name="more1_4[]" id="more1_4_'+j+'" value=""></td><td align="center"><input type="text" name="more1_5[]" id="more1_5_'+j+'" value=""></td><td align="center"><input type="text" name="more1_6[]" id="more1_6_'+j+'" value=""></td></tr>';
}
document.getElementById("mvadd_more1").innerHTML="<table width='100%' border=0 cellspacing=1 cellpadding=3>"+str+"</table>";
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#DBEAF5">
<tr><td align="center">设置1</td><td align="center">设置2</td><td align="center">设置3</td><td align="center">设置4</td><td align="center">设置5</td><td align="center">设置6</td></tr>
</table>
</td>
</tr>
<tr>
<td>
<?php
if($ecmsfirstpost==1)
{
?>
<table width='100%' border=0 cellspacing=1 cellpadding=3>
<?php
$editnum=2;
for($i=1;$i<=$editnum;$i++)
{
?>
<tr><td align="center"><input type="text" name="more1_1[]" id="more1_1_<?=$i?>" value=""></td><td align="center"><input type="text" name="more1_2[]" id="more1_2_<?=$i?>" value=""></td><td align="center"><input type="text" name="more1_3[]" id="more1_3_<?=$i?>" value=""></td><td align="center"><input type="text" name="more1_4[]" id="more1_4_<?=$i?>" value=""></td><td align="center"><input type="text" name="more1_5[]" id="more1_5_<?=$i?>" value=""></td><td align="center"><input type="text" name="more1_6[]" id="more1_6_<?=$i?>" value=""></td></tr>
<?php
}
?>
</table>
<?php
}
else
{
$editnum=0;
if($r['more1'])
{
$r['more1']=stripSlashes($r['more1']);
?>
<table width='100%' border=0 cellspacing=1 cellpadding=3>
<?php
//录入项
$j=0;
$mvf_record=explode('||||||',$r['more1']);
$mvf_count=count($mvf_record);
for($i=0;$i<$mvf_count;$i++)
{
$j=$i+1;
$mvf_field=explode("::::::",$mvf_record[$i]);
?>
<tr><td align="center"><input type="text" name="more1_1[]" id="more1_1_<?=$j?>" value="<?=$mvf_field[0]?>"> <input type="hidden" name="more1_mvid[]" id="more1_mvid_<?=$j?>" value="<?=$j?>"><input type="checkbox" name="more1_mvdelid[]" id="more1_mvdelid_<?=$j?>" value="<?=$j?>">删</td><td align="center"><input type="text" name="more1_2[]" id="more1_2_<?=$j?>" value="<?=$mvf_field[1]?>"></td><td align="center"><input type="text" name="more1_3[]" id="more1_3_<?=$j?>" value="<?=$mvf_field[2]?>"></td><td align="center"><input type="text" name="more1_4[]" id="more1_4_<?=$j?>" value="<?=$mvf_field[3]?>"></td><td align="center"><input type="text" name="more1_5[]" id="more1_5_<?=$j?>" value="<?=$mvf_field[4]?>"></td><td align="center"><input type="text" name="more1_6[]" id="more1_6_<?=$j?>" value="<?=$mvf_field[5]?>"></td></tr>
<?php
}
?>
</table>
<?php
$editnum=$j;
}
}
?>
</td>
</tr>
<tr>
<td height="25">扩展数量: <input name="mveditnum_more1" type="hidden" id="mveditnum_more1" value="<?=$editnum?>">
<input name="mvnum_more1" type="hidden" id="mvnum_more1" value="6">
<input name="mvmust_more1" type="hidden" id="mvmust_more1" value="1">
<input name="mvaddnum_more1" type="text" id="mvaddnum_more1" value="1" size="6"> <input type="button" name="Submit5" value="输出" οnclick="javascript:domvadd_more1();"></td>
</tr>
<tr>
<td id="mvadd_more1"></td>
</tr>
</table>
我在页面中需要写的代码 内容模板的代码
<tr>
<td class="vertical-text" rowspan="2" bgcolor='ffffff' style="text-align: center;">职 业 培 训</td>
</tr>
<tr>
<td bgcolor="ffffff">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#DBEAF5">
<tbody>
<tr>
<td align="center">发证单位</td>
<td align="center">证书编号</td>
<td align="center">证书种类</td>
<td align="center">发证内容</td>
<td align="center">发证日期</td>
<td align="center">有效期至</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tbody>
<?php
$morefr=explode('||||||',$navinfor[more1]);
$mfcount=count($morefr);
for($mfi=0;$mfi<$mfcount;$mfi++){
$morefrf=explode('::::::',$morefr[$mfi]);
?>
<tr>
<td align="center"><input type="text" name="more1_1[]" id="more1_1_<?=$mfi + 1?>" value="<?=$morefrf[0]?>"></td>
<td align="center"><input type="text" name="more1_2[]" id="more1_2_<?=$mfi + 1?>" value="<?=$morefrf[1]?>"></td>
<td align="center"><input type="text" name="more1_3[]" id="more1_3_<?=$mfi + 1?>" value="<?=$morefrf[2]?>"></td>
<td align="center"><input type="text" name="more1_4[]" id="more1_4_<?=$mfi + 1?>" value="<?=$morefrf[3]?>"></td>
<td align="center"><input type="date" name="more1_5[]" id="more1_5_<?=$mfi + 1?>" value="<?=$morefrf[4]?>"></td>
<td align="center"><input type="date" name="more1_6[]" id="more1_6_<?=$mfi + 1?>" value="<?=$morefrf[5]?>"></td>
</tr>
<?php
}
?>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
新增的部分代码
<tr>
<td class="vertical-text" rowspan="2" bgcolor='ffffff' style="text-align: center;">职 业 培 训</td>
</tr>
<tr>
<td bgcolor="ffffff">
<script>
function domvadd_more1() {
// 获取添加的数量
var addNum = parseInt(document.getElementById('mvaddnum_more1').value);
// 获取带有 table tbody.tbody1 元素
// var parentTd = document.querySelector('td.nav1');
var tableBody = document.querySelector('table tbody.tbody1');
// 循环添加指定数量的新行
for (var i = 0; i < addNum; i++) {
// 创建新的 <tr> 行
var newRow = document.createElement('tr');
newRow.innerHTML = '<td align="center"><input type="text" name="more1_1[]" value="" style="margin-top: 5px;"></td>' +
'<td align="center"><input type="text" name="more1_2[]" value="" style="margin-top: 5px;"></td>' +
'<td align="center" ><input type="text" name="more1_3[]" value="" style="margin-top: 5px;width:140px"></td>' +
'<td align="center"><input type="text" name="more1_4[]" value="" style="margin-top: 5px;"></td>' +
'<td align="center"><input type="date" name="more1_5[]" value="" style="margin-top: 5px;"></td>' +
'<td align="center"><input type="date" name="more1_6[]" value="" style="margin-top: 5px;"></td>' ;
// 将新行插入到 "扩展数量:" 的下面,使用 insertAdjacentElement 方法
// parentTd.parentNode.insertBefore(newRow, nextElement);
tableBody.appendChild(newRow);
}
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody class="tbody1">
<tr>
<td align="center">发证单位</td>
<td align="center">证书编号</td>
<td align="center">证书种类</td>
<td align="center">发证内容</td>
<td align="center">发证日期</td>
<td align="center">有效期至</td>
</tr>
<?php
$morefr=explode('||||||',$navinfor[more1]);
$mfcount=count($morefr);
for($mfi=0;$mfi<$mfcount;$mfi++){
$morefrf=explode('::::::',$morefr[$mfi]);
?>
<tr>
<td align="center">
<input type="text" name="more1_1[]" id="more1_1_<?=$mfi + 1?>" value="<?=$morefrf[0]?>">
</td>
<td align="center">
<input type="text" name="more1_2[]" id="more1_2_<?=$mfi + 1?>" value="<?=$morefrf[1]?>">
</td>
<td align="center">
<input type="text" name="more1_3[]" id="more1_3_<?=$mfi + 1?>" value="<?=$morefrf[2]?>" style="width: 140px;">
</td>
<td align="center">
<input type="text" name="more1_4[]" id="more1_3_<?=$mfi + 1?>" value="<?=$morefrf[2]?>">
</td>
<td align="center">
<input type="date" name="more1_5[]" id="more1_4_<?=$mfi + 1?>" value="<?=$morefrf[3]?>">
</td>
<td align="center">
<input type="date" name="more1_6[]" id="more1_5_<?=$mfi + 1?>" value="<?=$morefrf[4]?>">
</td>
</tr>
<?php
}
?>
<tr>
<td height="25" class="nav1">扩展数量: <input name="mveditnum_more1" type="hidden"
id="mveditnum_more1" value="3">
<input name="mvnum_more1" type="hidden" id="mvnum_more1" value="6">
<input name="mvmust_more1" type="hidden" id="mvmust_more1" value="1">
<input name="mvaddnum_more1" type="text" id="mvaddnum_more1" value="1" size="6">
<input type="button" name="Submit5" value="输出" onclick="javascript:domvadd_more1();">
</td>
</tr>
</tbody>
</table>
</td>
</tr>
我写的修改时在PHP中写的,修改的代码
<tr>
<td class="vertical-text" rowspan="2" bgcolor='ffffff' style="text-align: center;">职 业 培 训</td>
</tr>
<tr>
<td bgcolor="ffffff" class="nav1">
<script>
function domvadd_more1() {
// 获取添加的数量
var addNum = parseInt(document.getElementById('mvaddnum_more1').value);
// 获取带有 table tbody.tbody1 元素
// var parentTd = document.querySelector('td.nav1');
var tableBody = document.querySelector('table tbody.tbody1');
// 循环添加指定数量的新行
for (var i = 0; i < addNum; i++) {
// 创建新的 <tr> 行
var newRow = document.createElement('tr');
newRow.innerHTML = '<td align="center"><input type="text" name="more1_1[]" value="" style="margin-top: 5px;"></td>' +
'<td align="center"><input type="text" name="more1_2[]" value="" style="margin-top: 5px;"></td>' +
'<td align="center" ><input type="text" name="more1_3[]" value="" style="margin-top: 5px;width:140px"></td>' +
'<td align="center"><input type="text" name="more1_4[]" value="" style="margin-top: 5px;"></td>' +
'<td align="center"><input type="date" name="more1_5[]" value="" style="margin-top: 5px;"></td>' +
'<td align="center"><input type="date" name="more1_6[]" value="" style="margin-top: 5px;"></td>' ;
// 将新行插入到 "扩展数量:" 的下面,使用 insertAdjacentElement 方法
// parentTd.parentNode.insertBefore(newRow, nextElement);
tableBody.appendChild(newRow);
}
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody class="tbody1">
<tr>
<td align="center">发证单位</td>
<td align="center">证书编号</td>
<td align="center">证书种类</td>
<td align="center">发证内容</td>
<td align="center">发证日期</td>
<td align="center">有效期至</td>
</tr>
<?php
$morefr = explode('||||||', $row['more1']); // 使用'||||||'作为分隔符将$row['more1']中的字符串分割成数组$morefr
$mfcount = count($morefr);
for ($mfi = 0; $mfi < $mfcount; $mfi++) {
$morefrf = explode('::::::', $morefr[$mfi]);
$value_to_display = isset($morefrf[0]) ? htmlspecialchars($morefrf[0]) : ''; // 取出第一个元素作为输入框的初始值
?>
<tr>
<td align="center">
<input type="text" name="more1_1[]" id="more1_1_<?=$mfi + 1?>" value="<?=$morefrf[0]?>">
</td>
<td align="center">
<input type="text" name="more1_2[]" id="more1_2_<?=$mfi + 1?>" value="<?=$morefrf[1]?>">
</td>
<td align="center">
<input type="text" name="more1_3[]" id="more1_3_<?=$mfi + 1?>" value="<?=$morefrf[2]?>" style="width: 140px;">
</td>
<td align="center">
<input type="text" name="more1_4[]" id="more1_4_<?=$mfi + 1?>" value="<?=$morefrf[3]?>">
</td>
<td align="center">
<input type="date" name="more1_5[]" id="more1_5_<?=$mfi + 1?>" value="<?=$morefrf[4]?>">
</td>
<td align="center">
<input type="date" name="more1_6[]" id="more1_6_<?=$mfi + 1?>" value="<?=$morefrf[5]?>">
</td>
</tr>
<?php
}
?>
<tr>
<td height="25" >扩展数量: <input name="mveditnum_more1" type="hidden"
id="mveditnum_more1" value="3">
<input name="mvnum_more1" type="hidden" id="mvnum_more1" value="6">
<input name="mvmust_more1" type="hidden" id="mvmust_more1" value="1">
<input name="mvaddnum_more1" type="text" id="mvaddnum_more1" value="1" size="6">
<input type="button" name="Submit5" value="输出" onclick="javascript:domvadd_more1();">
</td>
</tr>
</tbody>
</table>
</td>
</tr>