在myeclipse2014里新建一个HTML5版本的html文件,简单编辑后用火狐打开却发现中文乱码。如果是新建HTML4.01版本则不会出现这样的问题。这与MyEclipse在new html文件自动生成的代码有关。如果是new html5版本的,默认生成的<meta>标签内代码如下:
1.<meta name="keywords" content="keyword1,keyword2,keyword3">
2.<meta name="description" content="this is my page">
3.<meta name="content-type" content="text/html; charset=UTF-8">
而html4.01版本的则是
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
结合HTML5与HTML4.01的区别:
在起一段代码后面添加:<meta charset="UTF-8">即可解决。(charset是HTML5新增的属性,HTML5与HTML4.01在<meta>标签处的异同参见:<a target=_blank href="http://www.w3school.com.cn/html5/html5_meta.asp">http://www.w3school.com.cn/html5/html5_meta.asp</a>)
第二种方法,将3.<meta name="content-type" content="text/html; charset=UTF-8">中的UTF-8改成GBK也可以解决(具体为什么还没弄清楚)