以下是源码,通过调试发现,输出的html代码是正确的,如何显示在页面上,是前台的问题吗
public string strhtml()
{
StringBuilder htmltext = new StringBuilder();
DataTable ItemCount = BLL.HomeMgr.LoadURL();
if (ItemCount.Rows.Count < 10)
{
htmltext.Append("<table>");
htmltext.Append("<tr>");
htmltext.Append("<td>");
foreach (DataRow row in ItemCount.Rows)
{
htmltext.Append("<li><a href=\"");
htmltext.Append(row["URL"]);
htmltext.Append("\" target=\"_blank\">");
htmltext.Append(row["ItemName"]);
htmltext.Append("</a></li>");
}
htmltext.Append("</td>");
htmltext.Append("</tr>");
htmltext.Append("</table>");
}
else if (ItemCount.Rows.Count > 10 && ItemCount.Rows.Count < 20)
{
}
else
{
}
return htmltext.ToString();
}
<div id="html">
<%strhtml();%>
</div>
把函数结果拼到 aspx 的输出中要用表达式书写方式 <%= strhtml() %>
而不是脚本书写方式 <% strhtml(); %>
。
<%=strhtml();%>前面少了个=号,而且你确定你的框架支持后台返回值在前台jsp页面可以接收到吗,不需要先request.setAttribute。
写个js,getElementById('html').innnerHTML=<%strhtml();%>