为特定的div设置字符集 [英] Setting charset for a specific div

查看:94
本文介绍了为特定的div设置字符集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为特定的div分配一个字符集?这样一来,您就可以在页面上拥有多个字符集。

Is it possible to assign a charset for at specific div? So that you can have more than one charset on a page.

我目前正在通过JS将文本片段导入到我的网站中,其中一些文本需要使用UTF -8个字符集。为了确保我的文字正确显示在包含的每个页面上(有时是外部站点),我强制将metatag插入所有站点。

I'm currently importing snippets of text to my site via JS, and some of this text requires the UTF-8 charset. To be sure that my text is shown right on every page it is included (Sometimes external sites), I force the metatag into all the sites.

是否可以申请

Is it possible to apply this charset to only a specific div, span or something like that?

推荐答案

不,不是,也完全没有必要。

No it is not, and it also entirely unnecessary.

< meta> 元素声明一个字符集,或者更好的是,等效的HTTP标头仅在这里提供帮助浏览器会正确解释 HTML文本。浏览器完成此操作后,便会从中构造出一个DOM,从此以后,您实际上可以将文本视为没有具体字符集。出于所有目的和目的,文本在DOM中以 text 的形式存在,而不是必须由字符集解码器解释的二进制表示形式。

The <meta> element declaring a charset or, better, the equivalent HTTP header is only there to help the browser correctly interpret the HTML text. Once the browser has done so, it constructs a DOM out of it and you may essentially treat the text as having no concrete charset after this point. For all intends and purposes the text exists as text in the DOM, not as binary representation which must be interpreted by a charset decoder.

何时您通过Javascript向DOM中添加新内容时,同样的想法也适用。浏览器需要通过HTTP提取新内容,并且内容的编码应由HTTP标头表示。浏览器可以基于此将文本从特定的编码转换为 DOM文本,之后不再需要使用哪种编码。

When you're adding new content to the DOM via Javascript, the same ideas apply. The browser needs to fetch the new content via HTTP and the content's encoding should be denoted by an HTTP header. The browser can convert the text from the specific encoding to "DOM text" based on that, after which is doesn't matter anymore what encoding it was in.

因此,您可以完美地混合和匹配来自在同一页面/ DOM中的不同HTTP响应中提供的来自不同来源的编码,而不必担心全局编码。

Therefore, you can perfectly mix and match encodings from different sources being delivered in separate HTTP responses within the same page/DOM without having to worry about a "global" encoding.

这篇关于为特定的div设置字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆