动态添加Marquee标签,并动态赋值与属性
Posted ***满满***
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动态添加Marquee标签,并动态赋值与属性相关的知识,希望对你有一定的参考价值。
前台加载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 [email protected]");
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;
}
以上是关于动态添加Marquee标签,并动态赋值与属性的主要内容,如果未能解决你的问题,请参考以下文章