使用Java删除HTML删除对齐

时间:2010-09-22 11:05:01

标签: html java htmleditorkit

我在删除对齐方面遇到问题在HTML文档中。

 <html>
  <head>

  </head>
  <body>
    <p style="margin-top: 0" align="center">
      Hello World
    </p>
    <p style="margin-top: 0" align="center">
      Java World
    </p>
  </body>
</html>

我的问题是如何删除第一段的对齐而不影响第二段。如果我使用正则表达式,它将删除第二个para的对齐。我真的很同意你对这个问题的任何评论。

2 个答案:

答案 0 :(得分:1)

使用replaceFirst功能。

答案 1 :(得分:0)

我想告诉你另一种方式。使用CSS伪类::first-child非常简单。根据您的上述代码:


body p:first-child { text-align: left !important; }

第二件事是使用JavaScript或任何JS库(如jQuery)从第一个p元素中删除此属性,例如:


$(document).ready(function(){
    $("p").first().css("text-align","left");
});