62,041
社区成员
发帖
与我相关
我的任务
分享
$('div.button').click(function(){
//增大或减小字体
var $speech=$('div.speech');
var currentSize=$speech.css('fontSize');
//alert(currentSize);
var num=parseFloat(currentSize,10);
//alert(num);//这是返回的是数字
var unit=currentSize.slice(-2);
//alert(unit);//这里反回的是PX..
if(this.id=='switcher-large'){
num*=1.5;
}else if(this.id=='switcher-small'){
num/=1.5;
}
$speech.css('fontSize',num+unit);//num+unit就等价于数字+px(例如22px)
});