- static private string htmlTemplate(string body, string title, List<string> jsFiles, List<string> CSSFiles)
- {
- string css = null;
- string js = null;
- if (body == null)
- {
- body = @"";
- }
- if (title == null)
- {
- title = @"";
- }
- if (jsFiles != null && jsFiles.Count > 0)
- {
- var sbjs = new StringBuilder();
- foreach(var file in jsFiles)
- {
- sbjs.Append(@"<script src=""").Append(file).Append(@"""></script>");
- }
- js = sbjs.ToString();
- }
- if (cssFiles != null && cssFiles.Count > 0)
- {
- var sbcss = new StringBuilder();
- foreach(var file in cssFiles)
- {
- sbcss.Append(@"<link ">");
- }
- css = sbcss.ToString();
- }
- var sb = new StringBuilder();
- sb.Append(@"<!DOCTYPE html><html><head>")
- .Append(@"<meta http-equiv=""Content-Type"" content=""text/html; charset=UTF-8"">") // 显示中文
- .Append(@"<title>").Append(title).Append(@"</title>");
- if (!String.IsNullOrEmpty(js))
- {
- sb.Append(js);
- }
- if (!String.IsNullOrEmpty(css))
- {
- sb.Append(css);
- }
- sb.Append(@"</head><body>")
- .Append(@"<h1>").Append(title).Append(@"</h1>");
- sb.Append(body);
- sb.Append(@"</body></html>");
- return sb.ToString();
- }
- //该片段来自于http://www.codesnippet.cn/detail/0604201614634.html
来源: http://www.codesnippet.cn/detail/0604201614634.html