function getCharset(){
var paras = document.getElementsByTagName("meta");//js获取所有meta
//var paras=$('meta');//jq获取
var regGbk=/(gbk|GB2312)/i;//适配gbk或者gbxxxx
var regUtf=/(utf8|utf-8)/i;//匹配utf-8编码的两种写法
var thisCharset='';
for(var i=0;i<paras.length;i++){
var content =paras[i].getAttribute("content");
var httpEquiv = paras[i].getAttribute("http-equiv");
var charset=paras[i].getAttribute("charset");
if(httpEquiv&&content.match(regGbk)){//gbk
var charset=paras[i].getAttribute("content");
thisCharset='gbk';
}else if(charset&&charset.match(regUtf)){//utf-8
var charset=paras[i].getAttribute("charset");
thisCharset='utf-8';
}
}
return {'charset':thisCharset};
}
getCharset();
//{charset: "utf-8"}