Jquery不会让我添加$(this).html();

我希望比我更聪明的人能想出来,我觉得我真的很亲近……

在这里查看: http//jsfiddle.net/9rjW3/4/

这是我添加的Jquery

$('tr:gt(0)').each(function () { $(this).find('td:eq(2)').html(function () { if($('span').height() > 18) return $(this).html().replace('@','\n@'); else return 'this'; }) }) 

它有效,但唯一的问题是我还没弄明白如何将“this”更改为单元格的值…

当我试图改变

 return 'this'; 

 return $(this).html(); 

它不起作用,有什么建议吗?

我个人建议:

 $('tr + tr td:nth-child(3) span').html(function(i,h){ return $(this).height() > 18 ? h.replace(/@/g, '\n@') : h; }); 

JS小提琴演示 。

你不需要$(this).html ,你已经可以直接使用了。

 $('tr:gt(0)').each(function () { $(this).find('td:eq(2)').html(function (index, html) { if($('span').height() > 18) { return html.replace('@', '
@'); } else { return html; } }); });

@之前正确添加\n ,您可以在调试控制台中看到它。 你可能反而意味着要添加一个

更新:

您在某个高度之后进行换行的逻辑不起作用,因为除非您专门设置表格单元格的宽度,否则文本将永远不会换入表格单元格。 您必须始终附加中断,或者为该列设置一个宽度。