html dom characterset属性表示与e8e496c15ba93d81f6ea4fe5f55a2244元素的charset属性相关联的字符集。默认情况下,html文档的字符集为utf-8。
characterset属性以字符串格式返回html文档的字符编码。用户可以使用html中的charset属性或dom characterset属性覆盖网页的默认字符集。
语法characterset属性的语法如下:
document.characterset
example让我们来看一个html dom characterset属性的例子−
<!doctype html><html><body><p>click the below button to know the encoding of this html document</p><button onclick="encode()">check encode</button><p id="sample"></p><script> function encode() { var x = document.characterset; document.getelementbyid("sample").innerhtml = "the character encoding used is "+ x; }</script></body></html>
输出这将产生以下输出 −
点击check encode按钮 −
在上面的例子中 −
我们首先创建了一个按钮check encode,当用户点击时将执行encode()函数 −
<button onclick="encode()">check encode</button>
encode()方法将使用文档的characterset属性获取文档的字符编码,并将其赋值给变量x。然后,使用paragraph元素的innerhtml()方法将编码显示在id为“sample”的段落元素中,并将一些文本和附加的变量x分配给它 −
function encode() { var x = document.characterset; document.getelementbyid("sample").innerhtml = "the character encoding used is "+ x;}
以上就是html dom characterset 属性html dom characterset 属性返回当前文档的字符编码集的详细内容。