[英]remove anchor elements added from the server side
I am adding some html to div from sever side.我正在从服务器端向 div 添加一些 html。 I want to remove all anchor tags from that html but preserve their text when I am sending that html back to the server on the click of button.我想从该 html 中删除所有锚标记,但在单击按钮将该 html 发送回服务器时保留它们的文本。
Below is the Html I am adding to div from server:下面是我从服务器添加到 div 的 Html:
<p>
<strong><u>Database Decommission Notice – IMPORTANT NOTIFICATION</u></strong>
</p>
<p>
<strong>FOLLOWING DATABASE(S) ARE SCHEDULED TO BE DECOMMISSIONED in 4 WEEKS </strong>
</p>
<p>
<strong><a href="#">Why have you received this email?</a></strong>
</p>
<p>
<a href="#">You are receiving this email as because you are an ITAO/ITAO delegate/CSM/CSM-1/key technical contact for database(s) that are scheduled to be decommissioned by 30. Below are the applications you have been identified.?</a>
</p>
Can someone please help to achieve this?有人可以帮助实现这一目标吗?
Edit: I just realized that I am not even able to select anchor tags.编辑:我刚刚意识到我什至无法选择锚标签。 I am not sure if is it because I added this complete html from the server side.我不确定是不是因为我从服务器端添加了这个完整的 html。 I tried this but it just doesn't go inside loop.我试过这个,但它只是没有进入循环。
$('#btnSaveTemplate').click(function () {
var emailbody = $('#divEmailBody');
var atag = emailbody.children('a[href=#');
$(atag).each(function () {
alert($(this).contents());
});
});
您可以通过以下方式使用 jQuery 执行此操作:
$('a[href="#"]').contents().unwrap();
You can use replaceWith您可以使用replaceWith
$('a').replaceWith(function(){
return $(this).contents();
});
您可以在 Asp.NET 中使用 Regex,如下所示:
Regex.Replace(str, @"<a\b[^>]+>([^<]*(?:(?!</a)<[^<]*)*)</a>", "$1")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.