现在后台有一个添加文章的功能,文章是用复文本框来添加的内容,数据库的字段类型是text,添加的话,会把文章里面字体的CSS样式什么的也保存下来了,可是现在我要在前台显示文章的内容模块的时候想移除里面的css样式。求解答。

解决方案 »

  1.   

    你说的样式是指什么呢?类似这样的<b>粗体</b>?
    你只要文字,可以用正则去除html标记 

    ContentHtml= Regex.Replace(ContentHtml,"<[^>]*>", "");
    ContentHtml= Regex.Replace(ContentHtml,"\\s+", " ");
      

  2.   

    或者有没有强制设定div中字体的颜色和大小的,就是说不管这个div里面的字体前面有没有其他定义颜色和大小的,都统一用一个。
      

  3.   

    你还是都去掉html,然后在每段落的前后加上div
      

  4.   


     
            /// <summary>
            /// //将HTML去除
            /// </summary>
            /// <param name="Htmlstring">需要处理的html</param>
            /// <returns></returns>
            public static string DelHTML(string Htmlstring)
            {
                Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"-->", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"<!--.*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            //Htmlstring =System.Text.RegularExpressions. Regex.Replace(Htmlstring,@"<A>.*</A>","");            //Htmlstring =System.Text.RegularExpressions. Regex.Replace(Htmlstring,@"<[a-zA-Z]*=\.[a-zA-Z]*\?[a-zA-Z]+=\d&\w=%[a-zA-Z]*|[A-Z0-9]","");            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(amp|#38);", "&", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(lt|#60);", "<", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(gt|#62);", ">", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", System.Text.RegularExpressions.RegexOptions.IgnoreCase);            Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&#(\d+);", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                Htmlstring.Replace("<", "");            Htmlstring.Replace(">", "");            Htmlstring.Replace("\r\n", "");
                return Htmlstring;        }
      

  5.   

    可以添加一格DIV用jquery去掉代码里最里面的style属性 例如
    <div id=ASD >
    <table >
    <tr>
    <td>
    <span Class=FR>a href=/Class/MYSHOP.asp?ID=451><span style='color:#000080;background:#800080'>我的商场</span></a>
    </span>
    </td>
    </tr>
    </table>
    </div>
      

  6.   

    不行你可以这样尝试:$(document).ready(function(){
     $('#msg5 .syzx span').removeAttr("style");
     });
      

  7.   

    这个需要HTML转换 /// <summary>
            /// 插入SQL时替换字符
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string Encode(string str)
            {
                str = str.Replace("'", "''");
                str = str.Replace("\"", "&quot;");
                str = str.Replace("<", "&lt;");
                str = str.Replace(">", "&gt;");
                str = str.Replace("\n", "<br>");
                str = str.Replace("“", "&ldquo;");
                str = str.Replace("”", "&rdquo;");
                return str;
            }        /// <summary>
            /// 取SQL值时还原字符
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string Decode(string str)
            {
                str = str.Replace("&rdquo;", "”");
                str = str.Replace("&ldquo;", "“");
                str = str.Replace("<br>", "\n");
                str = str.Replace("&gt;", ">");
                str = str.Replace("&lt;", "<");
                str = str.Replace("&quot;", "\"");
                str = str.Replace("''", "'");
                return str;
            }