如何设置网页的content-type避免乱码?

最好把
<meta http-equiv="content-type" content="text/html;charset=utf-8">
放在第一行,这样的话,在浏览器读到中文之前,就能读到html文档的编码类型

1.下面这种方式容易导致乱码:
<head>
  
<title>博客后台管理 - 博客园</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <link rel="stylesheet" type="text/css" href="http://common.cnblogs.com/blog/css/admin.css?id=20120902"/>
  <script src="http://common.cnblogs.com/script/jquery.js" type="text/javascript"></script>
  <script src="http://common.cnblogs.com/script/json2.js" type="text/javascript"></script>
  <script type="text/javascript" src="http://common.cnblogs.com/blog/script/jquery.cnblogs.thickbox.js"></script>
  <script type="text/javascript" src="http://common.cnblogs.com/blog/script/admin.js?id=20120902"></script>
</head>

2.下面这种方式不容易出现乱码:
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  
<title>博客后台管理 - 博客园</title>
  <link rel="stylesheet" type="text/css" href="http://common.cnblogs.com/blog/css/admin.css?id=20120902"/>
  <script src="http://common.cnblogs.com/script/jquery.js" type="text/javascript"></script>
  <script src="http://common.cnblogs.com/script/json2.js" type="text/javascript"></script>
  <script type="text/javascript" src="http://common.cnblogs.com/blog/script/jquery.cnblogs.thickbox.js"></script>
  <script type="text/javascript" src="http://common.cnblogs.com/blog/script/admin.js?id=20120902"></script>
</head>
 
 

posted on 2012-09-06 17:51  kz2012  阅读(613)  评论(0编辑  收藏  举报

导航