在我这次制作Blog的新外观时,半于文章标题的字体设置一直不满意,不是宋体或者微软雅黑的英文难看,就是放大之后的宋体难看,于是利用JQuery写了下面的代码实现了中文用微软雅黑,英文用CalibriCalibri字体是难得的在12像素大小时看起来像11像素的字体。,实现的原理如下:
首先设置中文字体,然后将0x20~0x800x20~0x80是常见的所有半角字符之间的字符找出来,为它们加上i标签,而这里的标签i又被我设置成了英文字体Calibri,于是就达到目的了。
- $(".post .title a").each(function(){
- var oldHtml=this.innerHTML+"";
- var newHtml=oldHtml+"";
- var regex= new RegExp("[\\x20-\\x80]+","g");
- do{
- var match=regex.exec(oldHtml);
- if(match!=null)
- {
- regex.lastIndex=match.index+match[0].length;
- newHtml=newHtml.replace(match[0],"<i>"+match[0]+"</i>");
- }
- }
- while(match!=null)
- this.innerHTML=newHtml;
- });

