form表单的字符串进行utf-8编码

<form>表单有assept-charset属性。该属性规定字符的编码方式,默认是"unknown",与文档的字符集相同。

该属性除了Internet explorer几乎所有的浏览器支持。

语法:<form accept-charset="value">

    Value:常用的有utf-8和iso-8859-1。

因为Internet explorer不支持assept-charset属性,所以用JavaScript调用"dociument.charset="utf-8";"

方法一:

form表单中加入"accept-charset="utf-8" onsubmit="document.charset='utf-8'" "

其中onsubmit是表单按钮点击触发事件。相当于submit按钮上添加了一个onclick事件。

还可以用下面的方法(如果在页面只有一个表单时不推荐用这个方法)

    方法二:

<form action="" method="post/get">

….

<input type="submit" value="提交" onclick="subm()">

</form>

<script type="text/javascript">

Function subm(){

Document.charset="utf-8";

}

</script>

其中onclick是被点击事件。

该文章参考:

    http://www.w3school.com.cn/tags/att_form_accept_charset.asp

    http://www.tc711.com/2006/html/list-14506.html

将来的你,一定会感谢现在拼命努力的你!
原文地址:https://www.cnblogs.com/hugjil/p/6049236.html