简体   繁体   English

为什么我在asp.net到Z78E6221F6393D1356681DB398F14CE2EF2919ZFFEEE708代码中使用Response.Write()方法时页面中的css样式发生变化?

[英]Why does the css style in the page change when I use the Response.Write() method in asp.net to output the javascript code?

When I use the Response.Write() method in asp.net to output javascript code, such as the alert method, some of the css styles in this page are changed. When I use the Response.Write() method in asp.net to output javascript code, such as the alert method, some of the css styles in this page are changed.

For example,when I use the code in asp.net like this:例如,当我像这样使用 asp.net 中的代码时:

Response.Write("<script>alert('success!')</script>");

When I run the file, first it popup the alert message, but after the page loads completely, I find that the font-size style is changed and becomes larger, but others don't change.当我运行文件时,首先它会弹出警告消息,但是在页面完全加载后,我发现font-size样式发生了变化并且变大了,但是其他的没有变化。

I know use the Page.ClientScript.RegisterStartupScript() method that can solve the issue, but I want to know what causes this problem .我知道使用Page.ClientScript.RegisterStartupScript()方法可以解决这个问题,但我想知道是什么导致了这个问题

That is because you are using Response.Write where you are not supposed to use it.那是因为您在不应该使用它的地方使用了Response.Write You are using it outside of the code that is generating the page content, which means that you put the Javascript code outside of the HTML document.您在生成页面内容的代码之外使用它,这意味着您将 Javascript 代码放在 HTML 文档之外。

When you have anything before the doctype tag, the doctype is ignored and the page is parsed as tag soup instead of as a valid document, and it is rendered using Quirks Mode instead of Standards Compliance Mode.当您在 doctype 标记之前有任何内容时,将忽略 doctype 并将页面解析为标记汤而不是有效文档,并使用 Quirks 模式而不是标准合规模式呈现。 This affects how the HTML and CSS is interpreted, as the browser tries to emulate an ancient browser version, including all non-standard quirks, and errors.这会影响 HTML 和 CSS 的解释方式,因为浏览器试图模拟一个古老的浏览器版本,包括所有非标准的怪癖和错误。 It will also use different default styles for the elements, which is the likely reason for the difference in font size that you see.它还将对元素使用不同的默认 styles,这可能是您看到的字体大小不同的原因。

Internet Explorer is especially sensetive when Quirks Mode is used.使用 Quirks 模式时,Internet Explorer 尤其敏感。 It will include the box model bug to try to be compatible with early versions of the browser.它将包含框 model 错误以尝试与早期版本的浏览器兼容。

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

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