如何保持字体大小总是150%页刷新后或打开页面? [英] How to keep font size always 150% after page refresh or open page again?

查看:140
本文介绍了如何保持字体大小总是150%页刷新后或打开页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两个按钮,允许用户更改我的网页中的文本的字体大小。它的工作很好,但刷新或重新打开页面后,字体大小总是回到正常大小。那么如何保持字体大小总是150%后刷新页面或重新打开?
这是我的jQuery代码:

I've create two button which allow users to change the font size of texts in my webpage.It's work nice, but after refresh or reopen the page the font size always back to the normal size. So how to keep font size always 150% after page refresh or reopen? Here is my jQuery code:

$(document).ready(function() {

$("#l").click(function() {

    $("p").css("font-size","150%");

});

$("#n").click(function() {

    $("p").css("font-size","100%");

})

});

推荐答案

已经提到使用 localStorage 尼古拉斯),但因为我已经完成了一个JSFiddle,我想我可能会包括它。代码如下:

It has already been mentioned to use localStorage (+1 @Nicholas), but as I was already about finished with a JSFiddle, I figured I might as well include it. The code is as follows:

if (localStorage.fontSize)
{
    $('p').css('fontSize', localStorage.fontSize);
}

$("#m").click(function () {
    $("p").css("font-size", "150%");
    localStorage.fontSize = '150%';
});

$("#n").click(function () {
    $("p").css("font-size", "100%");
    localStorage.fontSize = '100%';
});

这里是 < b> JSFiddle 。运行它几次,你会看到该值承载。

And here's the JSFiddle. Run it a few times and you'll see that the value carries across.

这篇关于如何保持字体大小总是150%页刷新后或打开页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆