1

我在这里有这个,想看看如何选择未标记的元素/文本。我想在以下示例中选择文本“j.smith”:

<td class='dev'>
  <u>assigned</u>
  j.smith
</td>

提前谢谢了。

4

2 回答 2

4

在CSS中你不能这样做。对于样式,您可以使用 jquery 来查找这样的内容:

$("td.dev").contents().filter(function(){ return this.nodeType != 3; }).css('color', 'red');
于 2012-09-07T18:07:04.197 回答
1

你不能因为“j.smith”文本不是一个元素,它只是一个属于它的 parent 的文本节点<td>

CSS4 中有一些提议可能允许与您正在寻找的行为类似的行为,但在此之前,解决方法是撤消对任何子元素的更改,如下所示:

td.dev { font-weight: bold; }
td > * { font-weight: normal; } /* this undoes the change to any children of the `<td>` */
于 2012-09-06T19:22:58.750 回答