[英]jQuery break out of table
我有一個標准的HTML格式表,通過Zend Framework動態生成內容。 從中我有一個問題在PHP內部改變表單。 所以我需要以某種方式改變表的外觀。 有了這個,我有一個元素出現在其中一行中,當這個元素出現時,我想要突破表,然后在它之后做一些事情,然后再次啟動表。
基本上我想注入相應的
</tbody></table>/*other stuff*/<table><tbody>
在包含我尋找的一個元素的行之后,在這種情況下是一個標簽。
我嘗試了$("label[for='theLable']").parents('tr').after('</tbody></table><br><table><tbody>')
似乎忽略了結束表部分添加br,然后為同一個表中的table和tbody做一個完整的打開/關閉標記我試圖突破所以inbetween tr標簽基本上它添加了這個新表
什么是接近這個概念的最佳方式?
用jsfiddle鏈接更新
您無法以您的思維方式真正修改文檔的HTML,因為它不是改變DOM的合法方式。
相反,我會創建一個新表並.append
你想要移動到它的行,它會自動從當前位置移動它們(而不是復制它們):
$(document).ready(function() {
var $trow = $('label[for="specialLabel"]').closest('tr'),
$table = $trow.closest('table');
$('<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));
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.