I'm trying to add a table row with ajax/jquery that has a form element in it. Everything works just fine if I set it without the ajax, but somehow everything inside the <form>
tag is just completely lost.
我正在尝试添加一个带有ajax / jquery的表行,其中包含一个表单元素。如果我在没有ajax的情况下设置它,一切正常,但不知何故,
I'm not sure where I'm losing the form (jquery's .html() is effectively the same as innerHTML right? If that's the case I suspect that's where I'm losing it).
我不知道我在哪里丢失表格(jquery的.html()实际上和innerHTML一样吗?如果是这样的话我怀疑那是我丢失它的地方)。
Anyway, here's some code:
无论如何,这里有一些代码:
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);
});
And in getwotrans.php: (paraphrased)
并在getwotrans.php :(转述)
<table>
<thead><tr><td>blahblah</td></tr></thead>
<tbody><form><tr><td><input></td></tr></form></tbody>
</table>
So what happens is I'll run the javascript function to add the row, and the row is added fine and I see the table headers, but the 'form' inside the tbody is just not there.
那么我将运行javascript函数来添加行,并且行添加正常并且我看到了表头,但是tbody中的'form'就不存在了。
3 个解决方案
#1
I had some simliar problem. I used a hidden form and javascript to copy the values of the row clicked to the hidden form elements and then submit the form via javascript. Maybe that's an idea.
我有一些类似的问题。我使用隐藏的表单和javascript来复制点击隐藏表单元素的行的值,然后通过javascript提交表单。也许这是一个想法。
#2
a form cannot be a child element of tbody
表单不能是tbody的子元素
#3
What happens when you put the form outside of the table?
当你把表格放在桌子外面时会发生什么?
<form><table>
<thead><tr><td>blahblah</td></tr></thead>
<tbody><tr><td><input></td></tr></tbody>
</table></form>
Just curious if this will fix the issue or not? It is odd that this would happen without something equally odd to fix it!
只是好奇这是否能解决这个问题?奇怪的是,如果没有同样奇怪的东西来修复它会发生这种情况!
#1
I had some simliar problem. I used a hidden form and javascript to copy the values of the row clicked to the hidden form elements and then submit the form via javascript. Maybe that's an idea.
我有一些类似的问题。我使用隐藏的表单和javascript来复制点击隐藏表单元素的行的值,然后通过javascript提交表单。也许这是一个想法。
#2
a form cannot be a child element of tbody
表单不能是tbody的子元素
#3
What happens when you put the form outside of the table?
当你把表格放在桌子外面时会发生什么?
<form><table>
<thead><tr><td>blahblah</td></tr></thead>
<tbody><tr><td><input></td></tr></tbody>
</table></form>
Just curious if this will fix the issue or not? It is odd that this would happen without something equally odd to fix it!
只是好奇这是否能解决这个问题?奇怪的是,如果没有同样奇怪的东西来修复它会发生这种情况!