前台加载js
$(function(){
var publishStr="<%=publishText%>"
var marqueeStr=" <marquee id=\"marquee0\" onmouseover=\"this.stop()\" onmouseout=\"this.start()\" direction=\""+direction+"\" scrollamount=\""+scrollamount+"\" scrolldelay=\""+scrolldelay+"\"></marquee>";
$("#pulishText_div").append(marqueeStr);
$("#marquee0").html(htmlDecode(publishStr));
})
对于publishText,是在后台htmlEncode编码得到的
//主界面-公告-滚动内容设置
private void NoticeDataGet(string CustomerId)
{
string sql = string.Format(@"SELECT ConfigName,Src FROM dbo.TVipMemebershipCenterConfig WHERE ConfigCode='publishText' AND status='1' AND CustomerId=@CustomerId");
var bllInfo = UnityInvoker.GetBLLInfo(CustomerId, DbKeys.Biz);
DbParameterList paras = new DbParameterList();
paras.Add("@CustomerId", SqlDbType.VarChar, 50, CustomerId);
DataSet dataSet = UnityInvoker.BLLInvoke<IBLL_SQLHelper>(DataInvokeMode.LANDriectDB).
FillData(bllInfo, sql,paras);
DataTable dt = dataSet.Tables["FzTable"];
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
publishText += "<a href=\\\"" + HttpUtility.HtmlEncode(dr["Src"].ConvertString()) + "\\\">" +HttpUtility.HtmlEncode(dr["ConfigName"]) + "</a><br>";
}
}
else {
publishText += "<a href=\\\"javascript:void(0)\\\">公告内容,公告内容</a><br>";
}
}
所以要展现既有便签,又通过编码过的字符串,就要在前台进行特殊处理,解码htmlDecode
function htmlEncode ( str ) {
var ele = document.createElement('div');
ele.appendChild( document.createTextNode( str ) );
return ele.innerHTML;
}
function htmlDecode ( str ) {
var ele = document.createElement('div');
ele.innerHTML = str;
return ele;
}