<script language="javascript" type="text/javascript">Hello World!</script>因為存在尖括號和關鍵字script,所以用常規方法是無法輸出的,必須轉換掉尖括號。用以下語句:Response.Write("<script language="javascript" type="text/javascript">Hello World!</script> ");結果是什麼都沒有輸出。所以必須得轉換尖括號。改用下面語句:Response.Write("<script language="javascript" type="text/javascript">Hello World!</script>");輸出結果:<script language="javascript" type="text/javascript">Hello World!</script>此題目的關鍵在於HTML和關鍵相互轉換,還有以下內容還需要轉換// <summary>// 功能:對錶 表單內容進行轉換HTML操作,// </summary>public static string HtmlCode(string s){string str = "";str = s.Replace(">", ">");str = s.Replace("<", "<");str = s.Replace(" ", " ");str = s.Replace("\n", "<br />");str = s.Replace("\r", "<br />");str = s.Replace("\r\n", "<br />");return str;}// <summary>// 功能:對錶 表單內容進行轉換HTML操作,// </summary>public static string CodeHtml(string s){string str = "";str = s.Replace(">", ">");str = s.Replace("<", "<");str = s.Replace(" ", " ");str = s.Replace("<br />", "\n");str = s.Replace("<br />", "\r");str = s.Replace("<br />", "\r\n");return str;}
<script language="javascript" type="text/javascript">Hello World!</script>因為存在尖括號和關鍵字script,所以用常規方法是無法輸出的,必須轉換掉尖括號。用以下語句:Response.Write("<script language="javascript" type="text/javascript">Hello World!</script> ");結果是什麼都沒有輸出。所以必須得轉換尖括號。改用下面語句:Response.Write("<script language="javascript" type="text/javascript">Hello World!</script>");輸出結果:<script language="javascript" type="text/javascript">Hello World!</script>此題目的關鍵在於HTML和關鍵相互轉換,還有以下內容還需要轉換// <summary>// 功能:對錶 表單內容進行轉換HTML操作,// </summary>public static string HtmlCode(string s){string str = "";str = s.Replace(">", ">");str = s.Replace("<", "<");str = s.Replace(" ", " ");str = s.Replace("\n", "<br />");str = s.Replace("\r", "<br />");str = s.Replace("\r\n", "<br />");return str;}// <summary>// 功能:對錶 表單內容進行轉換HTML操作,// </summary>public static string CodeHtml(string s){string str = "";str = s.Replace(">", ">");str = s.Replace("<", "<");str = s.Replace(" ", " ");str = s.Replace("<br />", "\n");str = s.Replace("<br />", "\r");str = s.Replace("<br />", "\r\n");return str;}