[英]Hiding an html attribute from codebehind
我有一個要在其中存儲html的字符串。
string receipt = "<html>
<head></head>
<body>
<table style="width: 100%">
<tr id="trInsuranceInfo" style="line-height: normal;">
</tr>
<tr id="trCorpInfo" style="line-height: normal;">
</tr>
<tr id="trInvoiceDetails" style="line-height: normal;">
</tr>
</table>
</body>
</html>
"
我發送此html作為電子郵件,在特定情況下必須從代碼中隱藏tr trInInceiceDetails。 即,當我通過電子郵件發送該HTML時,trInvoiceDetails應該不存在。
從代碼中隱藏tr的最佳方法是什么?
提前致謝。
string receipt = "<html>
<head></head>
<body>
<table style="width: 100%">
<tr id="trInsuranceInfo" style="line-height: normal;"></tr>
<tr id="trCorpInfo" style="line-height: normal;"></tr>
%row%
</table>
</body>
</html>"
接着:
if(condition)
receipt = receipt.Replace("%row%", "");
else
receipt = receipt.Replace("%row%", "<tr id='trInvoiceDetails' style='line-height: normal;'></tr>");
在tr trInvoiceDetails之前和之后分別添加一個節點[trInvoiceDetailsStart]和[trInvoiceDetailsEnd]。
寫一個regx:
receipt = receipt.Replace(Regex.Match(receipt, @"\[trInvoiceDetailsStart\].*\[trInvoiceDetailsEnd\]", RegexOptions.Singleline).Value, string.Empty)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.