1)在這裏,我正在做一個行的克隆......但是這個代碼只在eclipse中工作[即克隆工作]並且它也不工作任何瀏覽器。遞增克隆行中的輸入字段的值
2)如何獲取克隆行中文本框的值相同的解決方案,並使用jsp和servlet插入到數據庫中? 我怎樣才能獲得具有相同名稱的那些值
3)我有servlet代碼從JSP只能得到單一值
String address_seq_num =request.getParameter("address_seq_num");
how can i get the value of address seq number in the cloned row fromjsp to servlet to insert into the next row of a table in the database.
4)如果我提到「文檔類型」這個代碼,也不會在Eclipse還..... 請指導我的工作......
的JavaScript
function clonetable() {
var x=document.getElementById("main_table"); //get the table
var rowCount = x.rows.length;
var row = document.getElementById("table_row_clone"); // find row to copy
var table = document.getElementById("table_body"); // find table to append to
var clone = row.cloneNode(true); // copy children too
var tb1 = clone.document.getElementById("asn");//here i'm incrementing the value
tb1.value=rowCount+1;//of "address seq num " in the cloned row
clone.id = "abc"; // change id or other attributes/contents
table.appendChild(clone); // add new row to end of table
}
function deltable() {
var x = document.getElementById("main_table"); //get the table
var rowCount = x.rows.length;
if (rowCount > 1) {
x.deleteRow(rowCount - 1);
} //delete the last row
}
HTML
<table id="main_table" align="center" style="width:75%">
<tbody id="table_body">
<tr id="table_row_clone">
<td>
<table align="center" style="width:100%">
<tr>
<td align="center">
<div style="border:3px solid silver;border-radius:5px;background-color:grey">
<table width="100%">
<tr>
<th align="center">Address Details</th>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div style="border:3px solid silver;border-radius:5px;background-color:#1E90FF">
<table align="center" style="width:99%">
<tr style="background-color:#1E90FF">
<td style="width:35%">
<table width="100%">
<tr id="slrow">
<td style="width:43%">Address Seq Num</td>
<td>
<input id="asn" style="width:60px" name="address_seq_num" type="text" value="1" readonly>
</td>
</tr>
</table>
</td>
<td width="49%" align="right">
<input style="width:80%" type="text" value="Reg.office/Primary Office">
</td>
<td align="right">
<input style="width:30px" type="button" value="+" onclick="clonetable()">
<input style="width:30px" type="button" value="-" onclick="deltable()">
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
你在哪裏遞增?我沒有在你的JS代碼中看到它 – greener
你的HTML標記是混亂的,很多元素還沒有被關閉。我建議。你發佈一個更乾淨的html標記,以正確關閉和結束元素標記。 –
感謝您的回覆......實際上,在這段代碼中,我想在克隆後在下一行增加「地址序號」......目前它的值是「1」......但我不知道該怎麼做。 ...我試過這段代碼var tb = document.getElementById(「asn」); tb.value = parseInt(tb.value,10)+ 1;它增加了值,但它也改變了第一行的值,在連續的additon ... – Gkp