$(function(){ $(".font-btn span").click(function(){ var thisEle = $(".font").css("font-size"); var textFontSize = parseFloat(thisEle , 10); var unit = thisEle.slice(-2); //获取单位 var cName = $(this).attr("class"); if(cName == "bigger"){ if( textFontSize <= 22 ){ textFontSize += 2; $(".font").css("letter-spacing", '5px'); } }else if(cName == "smaller"){ if( textFontSize >= 12 ){ textFontSize -= 2; $(".font").css("letter-spacing", '1px'); } } $(".font").css("font-size", textFontSize + unit); }); });