js 페이지 텍스트 크기 및 배경색 전환


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
    <script type="text/javascript" src="http://f3.v.veimg.cn//xz/answer/js/jquery-1.9.1.min.js">script>
    <script type="text/javascript">
        $(function () {
            function getCookie(name) {
                var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
                if (arr = document.cookie.match(reg))
                    return unescape(arr[2]);
                else
                    return null;
            }
            function setCookie(name, value) {
                var Days = 30;
                var exp = new Date();
                exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
                document.cookie = name + "=" + value + ";expires=" + exp.toGMTString();
            }
            var cookie_color_name="bg_color";
            var cookie_color_value=getCookie(cookie_color_name);
            console.log(" :"+cookie_color_value);
            if(cookie_color_value!=null) {
                $("#pText").css("background-color", cookie_color_value);
            }
            $("#btnRed").click(function () {
                $("#pText").css("background-color", "red");
                setCookie(cookie_color_name,"red");
            });
            $("#btnYellow").click(function () {
                $("#pText").css("background-color", "yellow");
                setCookie(cookie_color_name,"yellow");
            });
            var co_font="font_size";
            var co_value_size=getCookie(co_font);
            console.log(" :"+co_value_size);
            if(co_value_size!=null) {
                $("#pText").css("font-size",co_value_size);
            }
            $("#btnAdd").click(function () {
                $("#pText").css("font-size", "20px");
                setCookie(co_font,"20px");
            });
        });
    script>
head>
<body>
<div id="pText">
<p> p>
<p> p>
div>
<input id="btnSub" type="button" value=" "/>
<input id="btnAdd" type="button" value=" "/>
<input id="btnRed" type="button" value=" - "/>
<input id="btnYellow" type="button" value=" - "/>
body>
html>

좋은 웹페이지 즐겨찾기