如何将对象添加为表格 [英] How to add object as table..
问题描述
大家好,
我已经动态地添加了对象,但是现在我更改代码并想要添加与表相同的字段,但是当我要创建它时,请创建7个具有相同类型的对象.像7文字框.
我有很多次更改,但无法获取与我的表一样的所有对象(文本框,复选框,下拉列表,textarea)
这是我的代码.
如果您有任何解决方案,请告诉我.
Hi to all,
I have adding objects dynamically but now i change the code and want to add same fields as my table have but when i am going to create it create 7 objects with same type. like 7 text box.
i have changes lots of time but could not able to get exact all objects as my table( textbox, checkbox, dropdown, textarea )
Here is my code..
If any of you find any solution then pls let me know.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script>
var names = ["sl[]","in_terval[]","date[]","cities_visited[]","reimbursement_type[]","remarks[]","cities_visited[]","bills[]"];
function add(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for (var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
var newentry = document.createElement('textarea');
newentry.name = names[i];
newentry.type = "text";
newcell.appendChild(newentry);
}
}
</script>
</head>
<body>
<form method="post" action="add-dynamic8-send.php">
<table id="table">
<tr><th>Sl.No.</th><th>In Travel</th><th>Date</th><th>Cities Visited</th><th>Reimbursement Type</th><th>Remarks</th><th>Bills</th></tr>
<tr>
<td><input type="text" name="sl[]" id="sl" /> </td>
<td><input type="checkbox" name="in_terval[]" value="in_terval" /></td>
<td><input id="date" name="date[]" type="text" style=" width:100px;"/></td>
<td><input id="cities_visited" name="cities_visited[]" type="text" style="width:80;"/></td>
<td><select id="reimbursement_type" name="reimbursement_type[]" >
<option selected="selected" value="">--None--</option>
<option value="DA">DA</option>
<option value="Ticket">Ticket</option>
<option value="Misc">Misc </option>
</select></td>
<td><textarea id="remarks" name="remarks[]" type="text" style="width:220px; height:40px; "></textarea></td>
<td><input type="checkbox" name="bills[]" value="bills" /></td>
<!--
<td><textarea name = "job[]"></textarea></td>
<td><textarea name = "comment[]"></textarea></td>-->
<tr>
</table>
<input type ="button" value="add entry" onclick="add('table')"/>
<input type ="submit" id="submit" name="submit" value="submit"/>
</form>
</body>
</html>
感谢所有人..
Thanks to all..
推荐答案
您可以使用cloneNode
属性来避免额外的工作.例如-
You can make use ofcloneNode
property to avoid extra efforts. For example -
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
// "Clone" the tr element i.e. save a copy all of its attributes and values
// parameter value TRUE means copy all child nodes and its attributes recursively
// parameter value FALSE means just copy the current object and all of its attributes and values
var row = table.rows[rowCount-1].cloneNode(true);
table.appendChild(row);
还没有测试过这段代码,但是我以前用过.
希望这对您有帮助..
问候,
尼拉·索尼(Niral Soni)
Haven''t tested this piece of code but I have used this before.
Hope this will help you out..
Regards,
Niral Soni
var RowCount = 1;
var stat = false;
function AddRow() {
var LastRow="<TR><TD align=center><INPUT TYPE='text' name='Slno_"+RowCount+"' id='Slno_"+RowCount+"' size=1></TD><TD align=center><INPUT type='checkbox' name='in_travel_"+RowCount+"' ID='in_travel_"+RowCount+"' value='in_terval' size=10></TD><TD align=center><INPUT style='text-align:right' type='TEXT' name='date_"+RowCount+"' ID='date_"+RowCount+"' size=10></TD><TD align=center><textArea name='cities_visit_"+RowCount+"' ID='cities_visit_"+RowCount+"' cols=10></textArea></TD><td align=center><select id='reimbursement_"+RowCount+"' name='reimbursement_"+RowCount+"'><option selected='selected' value='None'>--None--</option><option value='DA'>DA</option><option value='Ticket'>Ticket</option><option value='Misc'>Misc</option></select></td><TD align=center><textArea name='Remark_"+RowCount+"' ID='Remark_"+RowCount+"' cols=10></textArea></TD><TD align=center><INPUT style='text-align:right' type='checkbox' name='bills_"+RowCount+"' ID='bills_"+RowCount+"' size=10></TD><TD align=center><INPUT style='text-align:right' type='submit' name='submit_"+RowCount+"' ID='submit_"+RowCount+"' value='Submit' size=10></TD><TD align=center></TR>";
(LastRow).find( :submit').click(getvalue).end().appendTo(' #SaleTable' span>); RowCount ++; } 函数getvalue(){ var row =
(LastRow).find(':submit').click(getvalue).end().appendTo('#SaleTable'); RowCount++; } function getvalue() { var row =
这篇关于如何将对象添加为表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!