我有一张宽桌子,我想将每行分成两行,在每个带有"column-6"类的单元格之后.
I have a wide table that I would like to split each row into two rows, after each cell with the class "column-6".
$( ".column-6" ).after( "</tr><tr class='secondary'>" );由于某些原因,它包含为:
For some reason it is included as:
<tr class="secondary"></tr>JS Fiddle示例: jsfiddle/xa9nk/1/
JS Fiddle example: jsfiddle/xa9nk/1/
推荐答案我认为您应该更改table的html.首先,您必须在所需位置插入令牌,然后用所需的字符串(</tr><tr class='secondary'>)执行令牌替换:
I think you should change the html of the table. First you have to insert the token at the positions you want, then perform the replacement of the token with the string you want (which is </tr><tr class='secondary'>):
var yourOtherFace = jQuery.noConflict(); var token = "sdfdskjflsfj34234ksldjfskdl"; yourOtherFace( ".column-6" ).after(token) .closest('table').html(function(i,oldHtml){ return oldHtml.replace(new RegExp(token,"g"), "</tr><tr class='secondary'>"); }); yourOtherFace('.column-1').attr('rowspan', '2');演示.
这是另一个使用纯正则表达式的解决方案,它没有先插入token,它可能会更短,但是我做了一个测试用例,看起来比第一个解决方案(使用token)慢了约40%.
Demo.
Here's another solution using pure Regex without inserting some token first, it may be shorter but I've made a test case and looks like it's about 40% slower than the first solution (using token).
演示2
这是性能测试.
更多推荐
如何使用jQuery将一个表行分为两个表行
发布评论