用jQuery向div中添加Html文本内容的简单实现
前台代码:
<linkhref="https://www.nhooo.com/Content/themes/base/jquery-ui.css"rel="stylesheet"type="text/css"/> <scriptsrc="https://www.nhooo.com/Scripts/jquery-1.4.4.min.js"type="text/javascript"></script> <scriptsrc="https://www.nhooo.com/Scripts/jquery-ui.js"type="text/javascript"></script>
functionPoeviewExcel(){
$.ajax(
{
url:"send/index",
type:"post",
success:function(data){
vardivshow=$("#showInfo2");
divshow.text("");//清空数据
divshow.append(data);//添加Html内容,不能用Text或Val
divshow.dialog({
title:"短信群发系统",
height:250,
width:580
});
}
}
);
returnfalse;
}
<ahref="#"onclick="returnPoeviewExcel()">预览数据</a> <divid="divPreview"style="display:none"> <textid="showInfo2"></text> </div>
后台(主要):
publicstringGetImportReport()
{
DataTabledt=this.ImportExcel();
stringcontent=String.Empty;
content=@"<tablewidth='550'border='0'cellspacing='0'cellpadding='0'bgcolor='#D2D2D2'>"
+"<trbgcolor='#336699'>"
+"<tdalign='center'><strong>序号</strong></td>"
+"<tdalign='center'><strong>目标手机号</strong></td>"
+"<tdalign='center'><strong>发送内容</strong></td>"
+"</tr>";
for(inti=0;i<dt.Rows.Count;i++)
{
content+="<tr>"
+"<tdwidth='50'align='center'>"+i.ToString()+"</td>"
+"<tdwidth='150'align='center'>"+dt.Rows[i][0].ToString()+"</td>"
+"<tdwidth='150'>"+dt.Rows[i][1].ToString()+"</td>"
+"</tr>";
}
content+="</table>";
returncontent;
}
说明:
divshow.append(data);//添加Html内容,不能用Text或Val
当然用after();会在该div中不断追加信息。
如果用Text:显示加载的文本内容;
如果用Val:点击链接第一次为空窗口,再点击才出现数据显示、
以上这篇用jQuery向div中添加Html文本内容的简单实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。