剥去<br/>标签并用<p> </p> <p>标签替换</p>

时间:2011-05-21 21:40:40

标签: javascript asp.net database

我的同事在asp.net中为我做了一些后端开发,我用文本区域做了CMS输入页面。问题是他们在生成页面时输出带有<br /><br />标记的段落。空间很大,我希望<p></p>,所以我可以控制间距等。我只想更改和替换ID <br />中的#FeaturedProjectNewsWrapper标记。

我在google上玩了​​一个小时左右,只找到了这个Javascript方法,我尝试将<br>更改为<br />但是它没有用,但是当我放入时它不起作用一页在页面上......

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function()
{$('body').html($('body').html().replace(/<br>\*/g,"</p><p>"));});
</script>

我也发现了一些PHP的东西,但这没什么用。我不确定如何真正使用ASP,所以一点点Javascript解决方案就会很好。

这是我的代码......

<div id="FeaturedProjectNewsWrapper">

<p class="DateStyle">20/05/2011</p>
<h2 class="ProjectNews">Employee of the Month</h2>

<p>LTM operate an Employee of the month scheme.  This was set up in 2009 to recognise and reward the hard work and dedication of individual employees across all LTM divisions.  Each month nominations are forwarded to Steven Laing who makes the final decision.  The employee is then notified and awarded £100 cash reward for their commitment and contribution to LTM’s ongoing success.<br /><br />The Employee of the Month recognition is not a substitute for our annual Employee of the Year award, the day-to-day positive recognition or reasonable pay and benefits the company has to offer.  It is really just another way of giving a special thank you to our top employee’s for their outstanding contribution in that month.<br /><br />Employee of the Month - April 2011: Zac Manning<br /><br />Congratulations go to Zac for receiving his Postgraduate Diploma in Surveying with distinction from the College of Estate Management, and also for his efforts at achieving the cHeRries Awards nominee stage for LTM Training Academy!</p>

<br style="clear:both;" />

</div>

如果有任何帮助,请输入以下网址

http://www.traditionalmasonry.co.uk/News/CompanyNewsArticle.aspx

非常感谢先进,我希望我提供了足够的信息。

3 个答案:

答案 0 :(得分:2)

如果您尊重将在您之后的其他人的工作,请不要在客户端使用javascript执行此操作。我知道asp看起来很糟糕,但最好清理那里的代码。在项目中进行全局搜索,找到包含ID为“FeaturedProjectNewsWrapper”的项目的页面。 asp页面通常类似于意大利面,但至少插入符号而不是段落的代码将很可能存在于同一个文件中。

答案 1 :(得分:0)

您遇到的问题是,使用<br/>标记时,段落会从中间标记,而<p>标记会围绕段落。考虑以下等价物:

<p>first</p>
<p>second</p>
<p>third</p>

first<br/>
second<br/>
third<br/>

如果您将<br/>替换为</p><p>,那么您将省略开头<p>和尾随</p>。要进行此转换,您必须能够插入开始<p>和结束</p>标记,否则它将无法正常工作。或者,您可以使用CSS控制<br/>间距。

HTH。

答案 2 :(得分:0)

尝试使用此正则表达式:/<br[^>]*>([^<]+)(<br>)/,"<p>$1</p>"