js表单字符集问题:javascript获取网页支持表单字符集的方法

发布时间:2020-04-15编辑:脚本学堂
js如何获取网页支持表单字符集的方法,设置正确的表单字符集,可以保证页面数据传递时不出现乱码,javascript中acceptcharset方法可用于获取表单字符集信息。

javascript获取网页支持表单字符集

javascript获取网页支持表单的字符集,可以通过表单的acceptcharset方法获得。

例子:
 

复制代码 代码示例:
<!doctype html>
<html>
<body>
<form id="frm1" accept-charset="iso-8859-1">
first name: <input type="text" name="fname" value="donald"><br>
last name: <input type="text" name="lname" value="duck"><br>
</form>
<p>the value of the accept-charset attribute is:
<script>
document.write(document.getelementbyid("frm1").acceptcharset)
</script>
</p>
</body>
</html>

输出:
the value of the accept-charset attribute is:iso-8859-1