Jquery 使页面上的元素在字体增加/减少后重置为默认大小

Jquery 使页面上的元素在字体增加/减少后重置为默认大小,jquery,Jquery,如何使页面上的元素在字体增加/减少后重置为默认值 我尝试了以下方法,但收效甚微(字体增加/减少有效): 这是我的密码: $(".resetFont").click(function () { }); $(".increaseFont").click(function () { var fontSize = getFontSize(); var newFontSize = fontSize + 1; setFontSize(newFontSize); retur

如何使页面上的元素在字体增加/减少后重置为默认值

我尝试了以下方法,但收效甚微(字体增加/减少有效):

这是我的密码:

$(".resetFont").click(function () {
});

$(".increaseFont").click(function () {
    var fontSize = getFontSize();
    var newFontSize = fontSize + 1;
    setFontSize(newFontSize);
    return false;
});

$(".decreaseFont").click(function () {
    var fontSize = getFontSize();
    var newFontSize = fontSize - 1;
    setFontSize(newFontSize);
    return false;
});

function getFontSize() {
    var currentSize = $("html").css("font-size");
    var currentSizeNumber = parseFloat(currentSize, 12);
    if (currentSizeNumber > 24) {
        currentSizeNumber = 24;
    }
    if (currentSizeNumber < 10) {
        currentSizeNumber = 10;
    }
    return currentSizeNumber;
}

function setFontSize(size) {
    $("html").css("font-size", size);
    $(".actualSize").html(size);
}
$(.resetFont”)。单击(函数(){
});
$(“.increaseFont”)。单击(函数(){
var fontSize=getFontSize();
var newFontSize=fontSize+1;
setFontSize(newFontSize);
返回false;
});
$(“.decreaseFont”)。单击(函数(){
var fontSize=getFontSize();
var newFontSize=fontSize-1;
setFontSize(newFontSize);
返回false;
});
函数getFontSize(){
var currentSize=$(“html”).css(“字体大小”);
var currentSizeNumber=parseFloat(currentSize,12);
如果(currentSizeNumber>24){
currentSizeNumber=24;
}
如果(currentSizeNumber<10){
currentSizeNumber=10;
}
返回当前大小枚举器;
}
函数setFontSize(大小){
$(“html”).css(“字体大小”,大小);
$(“.actualSize”).html(大小);
}

只需设置原始字体大小:

 $(".resetFont").click(function () {
      $("html").css("font-size", '24px');
 });

真的没有人得到这个吗?

什么是
尺寸
?为什么要将html内容设置为
。actualSize
@gdoron这是OP的帖子,似乎是一个指示字体大小的元素,当字体大小发生变化时需要更新
var defaultFontSize = $('html').css('font-size');
$(".resetFont").click(function () {

$("html").css("font-size", defaultFontSize);
    $(".actualSize").html(defaultFontSize );


});
 $(".resetFont").click(function () {
      $("html").css("font-size", '24px');
 });
$('.resetFont').click(function(){
    setFontSize('auto');
}