我从服务器端向div添加了一些html。我想从该html中删除所有锚标记,但是当我通过点击按钮将该html发送回服务器时,保留其文本。
以下是我从服务器添加到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>
有人可以帮助实现这个目标吗?
编辑: 我才意识到我甚至无法选择锚标签。我不确定是不是因为我从服务器端添加了这个完整的html。我试过这个,但它不会进入循环。
$('#btnSaveTemplate').click(function () {
var emailbody = $('#divEmailBody');
var atag = emailbody.children('a[href=#');
$(atag).each(function () {
alert($(this).contents());
});
});
答案 0 :(得分:0)
您可以通过jQuery执行此操作:
$('a[href="#"]').contents().unwrap();
答案 1 :(得分:0)
您可以使用replaceWith
$printMessage($string);
答案 2 :(得分:0)
您可以在Asp.NET中使用Regex,如下所示:
Regex.Replace(str, @"<a\b[^>]+>([^<]*(?:(?!</a)<[^<]*)*)</a>", "$1")