从数据库中读取的数据中包含特殊字符,‘,“等,将读取的数据包含在js脚本中,js无法执行,
如何解决?
strScript = "javascript:opener.document.all('" + Files[0] + "').value='" + Grid1.Items[i].Cells[0].Text + "';"
+ "opener.document.all('" + Files[1] + "').value='" + Grid1.Items[i].Cells[1].Text + "';"
+ "opener.document.all('" + Files[2] + "').value='" + Grid1.Items[i].Cells[2].Text + "';"
+ "window.close();";
Grid1.Items[i].Cells[3].Text = "<a href='#' onclick=\"" + strScript + "\">【选择】</a>";
——————————————————————————————————Grid1.Items[i].Cells[1].Text 中可能会包含特殊字符,导致js无法执行!
尝试了这样的方法,无法解决
public static string HtmlEncode(string theString)
{
theString = theString.Replace(">", ">");
theString = theString.Replace("<", "<");
theString = theString.Replace(" ", " ");
theString = theString.Replace(" ", " ");
theString = theString.Replace("\"", """);
theString = theString.Replace("\'", "'");
theString = theString.Replace("\n", "<br/> ");
return theString;
}
等待高手........
如何解决?
strScript = "javascript:opener.document.all('" + Files[0] + "').value='" + Grid1.Items[i].Cells[0].Text + "';"
+ "opener.document.all('" + Files[1] + "').value='" + Grid1.Items[i].Cells[1].Text + "';"
+ "opener.document.all('" + Files[2] + "').value='" + Grid1.Items[i].Cells[2].Text + "';"
+ "window.close();";
Grid1.Items[i].Cells[3].Text = "<a href='#' onclick=\"" + strScript + "\">【选择】</a>";
——————————————————————————————————Grid1.Items[i].Cells[1].Text 中可能会包含特殊字符,导致js无法执行!
尝试了这样的方法,无法解决
public static string HtmlEncode(string theString)
{
theString = theString.Replace(">", ">");
theString = theString.Replace("<", "<");
theString = theString.Replace(" ", " ");
theString = theString.Replace(" ", " ");
theString = theString.Replace("\"", """);
theString = theString.Replace("\'", "'");
theString = theString.Replace("\n", "<br/> ");
return theString;
}
等待高手........
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货