【发布时间】:2010-11-04 04:01:04
【问题描述】:
我正在尝试使用 ajax/jquery 添加一个表格行,其中包含一个表单元素。如果我在没有 ajax 的情况下设置它,一切都会正常工作,但不知何故,<form> 标记内的所有内容都完全丢失了。
我不确定我在哪里丢失了表单(jquery 的 .html() 实际上与 innerHTML 相同,对吗?如果是这种情况,我怀疑这就是我丢失它的地方)。
不管怎样,这里有一些代码:
var worow = document.getElementById('worow_' + row);
var wotable = document.getElementById('tbl_workorders');
// add a new row to the table underneath our existing row.
var newrow = wotable.insertRow(worow.rowIndex+1);
var x = newrow.insertCell(0);
// set up the row a little bit
x.colSpan = 13;
x.style.padding = '10px';
x.style.backgroundColor = '#ccc';
x.align = "center";
x.innerHTML = '<img src="/images/loading.gif" />';
// a little ajax cuz we're cool that way
$.post("getwotrans.php",
{
workorder: row
},
function(response)
{
// set the value of the row = response object from the AJAX
$(x).html(response);
});
在 getwotrans.php 中:(释义)
<table>
<thead><tr><td>blahblah</td></tr></thead>
<tbody><form><tr><td><input></td></tr></form></tbody>
</table>
所以发生的情况是我将运行 javascript 函数来添加行,并且行添加正常并且我看到表头,但是 tbody 内的“表单”不存在。
【问题讨论】:
-
这里有一些读物。 w3.org/TR/html401/struct/tables.html
-
哦,拜托,该表已被释义,可以快速描述我正在尝试做的事情。它的实际结构并不重要。不过谢谢你的冷嘲热讽。