将 文本格式标记 转化为 html格式标记
在做一个聊天记录的时候遇到这样一个问题,之前写入的带有特殊标记的文字,在写入数据库再读取的时候,带有html标记,
在后台调试,设置断点,取出的数据(hgjghj)(包括样式),
用文本可视化查看 为 :<FONT color=#e6421a>hgjghj</FONT>
用HTML可视化查看 为:<FONT color=#e6421a>hgjghj</FONT>
在js中利用 document.getElementById ("newmessage").innerHTML = str;将str赋值给newmessage控件时,显示的一直是:<FONT color=#e6421a>hgjghj</FONT>
如果要去掉font标记 ,只显示hgjghj
解决方法如下:
将str赋值给控件前,先经过以下方法处理。
public static string newStr(string oldStr)
{
oldStr = oldStr.Replace(" ", " ");
oldStr = oldStr.Replace("<", "<");
oldStr = oldStr.Replace(">", ">");
oldStr = oldStr.Replace("<br/>", "\n");
oldStr = oldStr.Replace(" ", "\t");
oldStr = oldStr.Replace(""", "\"");
return newStr;
}
这时在
用文本可视化查看 为 :<FONT color=#e6421a>hgjghj</FONT>
用HTML可视化查看 为:hgjghj
此时前台控件显示的就将是hgjghj (保留样式,不显示标记)
如果要去掉所有标记,同时去掉样式, 只要在经过上面的方法处理之后,在经过以下方法即可
function RemoveHTML(strText)
{
var regEx = /<[^>]*>/g;
&nb
相关文档:
using System.Text.RegularExpressions; //引入的命名空间
以下为引用的内容:
//清除HTML函数
public static string NoHTML(string Htmlstring)
{
//删除脚本
Htmlstr ......
第一种:
<script language="javascript" type="text/javascript">
window.location.href="login.jsp?backurl="+window.location.href;
</script>
第二种:
<script language="javascript">
alert("返回");
window.history.back ......
<p>: 格式化段落; <h1>,<h6> 标题; <blockquote>-- 引用的文本; <pre>--预先格式化好的文本;保留原有的格式.
<ol><dl><ul>:顺序列表,定义列表,无标号列表. <li>用以显示单个的元素; <dl><dt><dd></dd></dt><dl>
< ......
string tent = this.TextBox_info.Text.Replace("<", "<").Replace(">", ">").Replace(" ", " ").Trim().Replace("\n", "<br/>");
& ......
HWND H1,H2,H3,H4,hw;
H1=H2=H3=H4=hw=NULL;
H1=::FindWindow("TForm1",NULL);
if (H1) H2=::FindWindowEx(H1,NULL,"Shell Embedding",NULL);
if (H2) H3=::FindWindowEx(H2,NULL,"Shell DocObject View",NULL);
if (H3) H4=::FindWindowEx(H3,NULL,"Internet Explorer_Server",NULL) ......