[英]how to escape an anchor tag in html which eval
您能幫忙轉義一下嗎:
<p><%# Eval("Text") + <a class="story-link" href="<%# GetDocumentUrl() %>" target="_self"><%# Eval("ReadFullStoryTitle") %></a> %>
</p>
我已經嘗試過像下面,但不能正常工作:
<p><%# Eval("Text") + <a class="story-link" href="'<%# GetDocumentUrl() %>'" target="_self"><'%#Eval("ReadFullStoryTitle") %'></a> %></p>
您可以使用以下方法:
<p><%# Eval("Text") %> <a class="story-link" href='<%# GetDocumentUrl() %>' target="_self"><%#Eval("ReadFullStoryTitle") %></a></p>
您可以使用javascripts innerText
添加數據,它將正確地轉義它們。
<p id="data"><script>document.getElementById('data') .innerText= '<%# Eval("Text") + <a class="story-link" href="<%# GetDocumentUrl() %>" target="_self"><%# Eval("ReadFullStoryTitle") %></a> %>';</script></p>
您還可以使用after和::after
css content
屬性,如下所示
#data::after{ content: '<%# Eval("Text") + <a class="story-link" href="<%# GetDocumentUrl() %>" target="_self"><%# Eval("ReadFullStoryTitle") %></a> %>'; }
<p id="data"></p>
或者,您可以使用下面的p標記中的代碼進行轉義。
<p><%# Eval("Text") + <a class="story-link" href="<%# GetDocumentUrl() %>" target="_self"><%# Eval("ReadFullStoryTitle") %></a> %></p>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.