请帮帮我 这是我的C#代码背后的
SpecialOffersDiv.InnerHtml = "<div class="offer_box_wide">
<a href=""><img src="../images/p1.jpg" width="130" height="98" class="img_left" alt="" border="0" /></a>
<div class="offer_info"> <span>For Sale 150 000 $</span>
<p class="offer"> "Lorem ipsum dolor sit</p>
<div class="more"><a href="#">...more</a></div>
</div>
</div>";
答案 0 :(得分:3)
你的问题是由两件事引起的。首先,需要转义字符串中的双引号。其次,新线路需要妥善处理。有两种方法可以实现这一目标。
首先,您可以使用逐字字符串文字指示符,然后将字符串中的每个双引号标记加倍。
SpecialOffersDiv.InnerHtml = @"<div class=""offer_box_wide"">
<a href=""""><img src=""../images/p1.jpg"" width=""130"" height=""98"" class=""img_left"" alt="""" border=""0"" /></a>
<div class=""offer_info""> <span>For Sale 150 000 $</span>
<p class=""offer""> "Lorem ipsum dolor sit</p>
<div class=""more""><a href=""#"">...more</a></div>
</div>
</div>";
其次,您可以使用反斜杠转义双引号并将换行符更改为\ n:
SpecialOffersDiv.InnerHtml = "<div class=\"offer_box_wide\">\n" +
"<a href=\"\"><img src=\"../images/p1.jpg\" width=\"130\" height=\"98\" class=\"img_left\" alt=\"\" border=\"0\" /></a>\n" +
"<div class=\"offer_info\"><span>For Sale 150 000 $</span>\n<p class=\"offer\"> "Lorem ipsum dolor sit</p>\n" +
"<div class=\"more\"><a href=\"#\">...more</a></div>\n" +
"</div>\n" +
"<`div>";
我会说第一个,它看起来更好。
答案 1 :(得分:2)
String literals(特别参见示例string f & g
)
SpecialOffersDiv.InnerHtml = @"<div class=""offer_box_wide"">
<a href=""""><img src=""../images/p1.jpg"" width=""130"" height=""98"" class=""img_left"" alt="""" border=""0"" /></a>
<div class=""offer_info""> <span>For Sale 150 000 $</span>
<p class=""offer""> "Lorem ipsum dolor sit</p>
<div class=""more""><a href=""#"">...more</a></div>
</div>
</div>";