alert('2010061800'.replace(/(\d{4})(\d{2})(\d{2})(\d{2})/,function($0,$1,$2,$3,$4){
return $1+'-'+$2+'-'+$3+' '+({00:'上午','01':'下午'}[$4]);
}));
return $1+'-'+$2+'-'+$3+' '+({00:'上午','01':'下午'}[$4]);
}));
调试欢乐多
return $1+'-'+$2+'-'+$3+' '+({'00':'上午','01':'下午'}[$4]);
}));
00====>'00'
数字的属性别用数字 用字符串
var arr = "{ '00': '上午', '01': '下午' }";
alert('2010061800'.replace(/(\d{4})(\d{2})(\d{2})(\d{2})/, function($0, $1, $2, $3, $4) {
return $1 + '-' + $2 + '-' + $3 + ' ' + eval("(" + arr+ ")")[$4];
}));