我有4 td的表,用户可以通过点击按钮添加行,在每个td里面我有文本框,其中一个我有打开弹出窗口的按钮。当用户单击此按钮时,弹出窗口将显示复选框,在用户选中复选框后,它们的值将显示在父页面的文本框中,该页面位于按钮的同一td中。我的问题是,当我添加新行时,复选框的值仅出现在第一个文本框中,而不是出现在新行中,因为我想为每个添加的行分配动态ID,并将已复选复选框的值发布到它。我只使用Javascript,PHP和HTML。 这是我的parent.php代码:
<html>
<head>
<script>
function addRow(in_tbl_name)
{
var tbody = document.getElementById(in_tbl_name).getElementsByTagName("TBODY")[0];
// create row
var rrowCount = tbody.rows.length;
var row = document.createElement("TR");
var td1 = document.createElement("TD");
var strHtml1 = "<INPUT TYPE=\"text\" SIZE=\"255\" MAXLENGTH=\"255\" class=\"textborder\">";
td1.innerHTML=strHtml1 ;
var td2 = document.createElement("TD");
var strHtml2 = "<INPUT TYPE='text' name='ch' id='ch' class=\"textbordersmall\">" +"<INPUT TYPE='text' SIZE=\"30\" MAXLENGTH=\"255\" id='clo' name='clo' class=\"textbordersmall\">";
td2.innerHTML=strHtml2;
var td3 = document.createElement("TD");
var strHtml3 ="<textarea value='' overflow-Y='auto' width='20' height='10' name='txtName' readonly='readonly'></textarea>"+"<input type='submit' value='PLO'/>";
td3.innerHTML=strHtml3 ;
var td4= document.createElement("TD");
var strHtml4 = "<INPUT TYPE=\"text\" NAME=\"in_name\" SIZE=\"5\" MAXLENGTH=\"255\" class=\"textbordersmall\">";
td4.innerHTML=strHtml4 ;
// append data to row
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
row.appendChild(td4);
// append row to table
tbody.appendChild(row);
}}
function deleterow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
if (rowCount==1){return false;}
if (rowCount==2&&num==1){num++;}
else{
num--;
table.deleteRow(rowCount -1);
}}
</script>
</head>
<body>
<form action="pop.php" method="POST" name="login" onsubmit="process(); return false;">
<TABLE ID="tbl" width="570" border="1" cellspacing="0" cellpadding="0" align="center" class="st">
<TH WIDTH="400">Content</TH><TH WIDTH="57">CLO</TH><TH WIDTH="57">PLO</TH> <TH WIDTH="56">Week</TH>
<p align="center">
<INPUT TYPE="Button" onClick="addRow('tbl')" VALUE="Add Row">
<INPUT TYPE="Button" onClick="deleterow('tbl')" VALUE="delete Row"> </p>
</TABLE></form>
</body>
</html>
&#13;
这是我的pop.php代码:
<html>
<body>
<input type="checkbox" name="c[]" id="ddlNames" value="E1">E1
<br />
<input type="checkbox" name="c[]" id="ddlNames" value="E2">E2
<br />
<input type="checkbox" name="c[]" id="ddlNames" value="E3">E3
<br />
<p align="center"><input type="submit" value="Select" onclick="SetName()" /></p> </form>
<script type="text/javascript">
function SetName() {
var frm = document.forms[0];
var txt = "";
var i;
for (i = 0; i < frm.length; i++) {
if (frm[i].checked) {
txt = txt + frm[i].value + " ";
}
}
for (s=0; s<200; s++){
var txtName = window.opener.document.getElementById('txtName');
txtName.value = txt;
}
window.close();
}
</script>
<body>
</html>
&#13;