0

我正在尝试对齐表格中列的文本。为此,如果文本没有星号,我会尝试在文本中添加前导空格。

这是我想出的(不起作用):

$("table:eq(1) tr").find("td:eq(0)").text().index('*').css({ 'text-indent': '2pt'});

如果不是请建议,这是一种更好的方法吗?

例如:第一列中的数据现在看起来像

*S10054472  Active  50000       
11-506843   Active  95000       
12-59949    Active  12500       
12-5709     Active  12750       
*11-499979  Active  3232 

应该看起来像

*S10054472  Active  50000       
 11-506843  Active  95000       
 12-59949   Active  12500       
 12-5709    Active  12750       
*11-499979  Active  3232 
4

2 回答 2

1

尝试这个

脚本

$('table tr').find('td:first').filter(function(){
    return !$(this).text().match(/^\*/)
}).css('padding-left', '6px')

标记

  <table>
     <tr>
        <td>*S10054472</td>
        <td>Active</td>
        <td>50000</td>
     </tr>
     <tr>
        <td>11-506843</td>
        <td>Active</td>
        <td>95000</td>
     </tr>
  </table>

更新

一个不太密集的过滤功能

$('table tr').find('td:first').filter(function(){
    return this.innerHTML[0] != '*'
}).css('padding-left', '6px')
于 2013-04-24T23:28:41.317 回答
0

我认为这应该很简单:

$('table td:contains("*")').prepend(document.createTextNode(' '));

它需要document.createTextNode代替带有空格的简单字符串,因为 jQuery.prepend()需要 DOM 元素或 jQuery 对象。

于 2013-04-24T23:38:37.730 回答