如何使用jQuery将一个表行分为两个表行

编程入门 行业动态 更新时间:2024-10-12 03:18:18
本文介绍了如何使用jQuery将一个表行分为两个表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一张宽桌子,我想将每行分成两行,在每个带有"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将一个表行分为两个表行

本文发布于:2023-10-08 01:05:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471056.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   两个   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!