Javascript jQuery断开表
我有一个标准的HTML格式的表,它通过Zend框架动态生成内容。从这一点上,我有一个问题,在PHP端内部修改表单。所以我需要以某种方式改变桌子的外观。在这种情况下,我有一个元素出现在其中一行中,当这个元素出现时,我想跳出表,然后做一些事情,然后再次启动表 基本上,我想注入Javascript jQuery断开表,javascript,jquery,Javascript,Jquery,我有一个标准的HTML格式的表,它通过Zend框架动态生成内容。从这一点上,我有一个问题,在PHP端内部修改表单。所以我需要以某种方式改变桌子的外观。在这种情况下,我有一个元素出现在其中一行中,当这个元素出现时,我想跳出表,然后做一些事情,然后再次启动表 基本上,我想注入 /*other stuff*/在包含一个元素的行之后,在本例中,该元素是一个标签 我尝试了$(“label[for='theLable']])。parents('tr')。在('br>')之后,它似乎忽略了表的结尾部分,添加了
/*other stuff*/
在包含一个元素的行之后,在本例中,该元素是一个标签
我尝试了$(“label[for='theLable']])。parents('tr')。在('br>')
之后,它似乎忽略了表的结尾部分,添加了br,然后对同一个表中的表和tbody做了一个完整的打开/关闭标记,我试图打破这两个tr标记之间的界限,基本上它添加了这个新表
实现这一概念的最佳方式是什么
使用JSFIDLE链接更新
您不能按照自己的想法修改文档的HTML,因为这不是一种合法的更改DOM的方法 相反,我将创建一个新表并
.append
要移动到其中的行,这将自动将它们从当前位置移动(而不是复制):
$(文档).ready(函数(){
var$trow=$('label[for=“specialLabel”]”)。最近('tr'),
$table=$trow.closest('table');
$('').append($trow.nextAll().andSelf()).insertAfter($table);
});
这种方法在js中不起作用。如果表中没有太多行,可以执行以下操作:
var nextTable = $("table").after("/*other stuff*/<table id="nextTable"></table>");
//now you loop over the lines of your original table that you want to have after the "break", and move them to the nextTable:
var before = true;
$("table tr").each(function(){
if ($(this).has("[for='theLable']")) {
before = false;
}
if (!before) {
nextTable.append($(this));
}
});
var nextTable=$(“表”)。在(“/*其他内容*/”)之后;
//现在,您可以在“中断”之后循环原始表的行,并将它们移动到下一个表:
var before=真;
$(“表tr”)。每个(函数(){
if($(this).has(“[for='TheTable']”){
before=假;
}
如果(!之前){
追加($(this));
}
});
你能发布你的HTML和/或JSFIDLE示例吗?哇,这看起来很正确,我想如果我必须自己得出这个结论,我会再花一天时间来做。谢谢
var nextTable = $("table").after("/*other stuff*/<table id="nextTable"></table>");
//now you loop over the lines of your original table that you want to have after the "break", and move them to the nextTable:
var before = true;
$("table tr").each(function(){
if ($(this).has("[for='theLable']")) {
before = false;
}
if (!before) {
nextTable.append($(this));
}
});