从数据库中读取的数据中包含特殊字符,‘,“等,将读取的数据包含在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;
}
等待高手........
解决方案 »
- Fileupload地址栏不表示
- 寻求支付,计费解决方案
- <asp:FileUpload ID="FileUpload1" runat="server" Width="329px" onpropertychange="<% seturl(this.value) %>"/>
- 外部DLL项目 读取网站主程序的配置文件问题
- 求asp.net做一个表格的列子.
- 急,请有经验的朋友告诉我,安装VS2005,本本的最低配置是多少,我要新买本本了.
- 紧急求助,我想在短期内学习ASP就行,请问有哪个高人指点一下。
- 直接用前台导入excel的例子,用flex实现,可调取js实现与.net交互
- 最近又看到有不少人提问水晶报表的问题,请到以下载地址下载我写的C#实例
- 查询数据出来后,按datagrid的分页键浏缆下页时出问题!
- asp.net 访问控制
- 关于数据库insert操作时的w3wp.exe的cpu占用率问题
可以处理一下变量字符串使之匹配。
string str=".........";
str = str.Replace("'", "\\'");
str = str.Replace("\r", "\\r");
str = str.Replace("\n", "\\n");