繁体   English   中英

是什么将我的JavaScript代码中的'和'字符替换为'和'?

[英]What is replacing my ' and " characters in javascript code with ' and "?

来源(.Net 3.5)

  output.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert(\"In order to prevent loss of your work, you may only use the progress grids within the same section.\");return false");

在浏览器中呈现:

<a onclick="alert(&quot;In order to prevent loss of your work, you may only use the progress grids within the same section.&quot;);return false" href="myPage.aspx#1">

这意味着JavaScript将无法执行。

同样,如果我用单引号替换内部引号,则将其转义为'

在IIS 7版上运行

它似乎与浏览器无关(IE 8,9 FF 15,Safari 7,Chrome)

导致这种情况的是IIS或.Net配置。

当然,有趣的是,它昨晚运行良好,现已损坏。

有什么办法可以抑制这种行为?

这意味着JavaScript将无法执行。

不,不是。 它可以防止"在从终止HTML数据中的字符的属性值。

HTML解析器会将HTML解码为文本(将&quot;变成"等),然后将其传递给JavaScript解析器。

有什么办法可以抑制这种行为?

将第三个参数( fEncode )设置为AddAttribute为false。 这将破坏您的HTML(从而破坏您的脚本)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM