使用Cookies更改文本区域的字体大小
问题描述:
此刻,我已将字体大小功能添加到我的Textarea。使用Cookies更改文本区域的字体大小
它工作正常,但现在我想添加饼干。 这是我走到这一步:
var size=size2 + "px";
var size2=15;
function getCookie(c_name){var i,x,y,ARRcookies=document.cookie.split(";");for (i=0;i<ARRcookies.length;i++){x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);x=x.replace(/^\s+|\s+$/g,"");if (x==c_name){return unescape(y);}}}
function setCookie(c_name,value,exdays){var exdate=new Date();exdate.setDate(exdate.getDate() + exdays);var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());document.cookie=c_name + "=" + c_value;}
var cookiesize=getCookie('fontsize');
if(cookiesize!==undefined&&cookiesize!==""&&cookiesize!==null){
size2=cookiesize;
}
else{}
function add(){
size2++;
size=size2+"px";
if(size2 > 40){size2=40;}
setCookie('fontsize',size2,365);
$('#current').html("<b>"+size2+"</b>");
$('#curren').stop(true,true).animate({'top' : '0px'},500);
$('#curren').stop(true,true).delay(3500).animate({'top' : '-50px'},1500);
$('#code1').css('font-size', size2);
}
function less(){
size2--;
size=size2+"px";
if(size2 < 5){size2=5;}
setCookie('fontsize',size2,365);
$('#current').html("<b>"+size2+"</b>");
$('#curren').stop(true,true).animate({'top' : '0px'},500);
$('#curren').stop(true,true).delay(4000).animate({'top' : '-50px'},1500);
$('#code1').css('font-size', size2);
}
$(document).ready(function(){
$('#panel').html("<form method='post' name='pad' align='center'><textarea class='look' rows='11' id='code1' name='text' cols='58'></textarea><br></form>");
$('#current').html("<b>"+size2+"</b>");
$('#curren').stop(true,true).animate({'top' : '0px'},500);
$('#curren').stop(true,true).delay(4000).animate({'top' : '-50px'},1500);
$('#code1').css('font-size', size2);
});
function show(){
$('#curren').stop(true,true).animate({'top' : '0px'},500);
$('#curren').stop(true,true).delay(4000).animate({'top' : '-50px'},1500);
}
我没有给你们的HTML或CSS,但它不应该是必要的。 现在我所得到的是字体大小数字应该是的未定义消息。
希望你能帮助!
最好的问候,
肖恩
答
编辑:我现在看到一个错误。从这个切换这两个语句的顺序:
var size=size2 + "px";
var size2=15;
这样:
var size2=15;
var size=size2 + "px";
你被引用size2
它被定义之前。
而且,这里是一个代码建议:
更改此:
if(cookiesize!==undefined&&cookiesize!==""&&cookiesize!==null){
size2=cookiesize;
}
else{}
这样:
if (cookiesize) {
size2 = cookiesize;
}
if (cookiesize)
防止null
,undefined
,0
,false
和""
全部一张支票。我还建议你在你的代码中使用一些空格和新行,以使其更具可读性。
+0
在前两行中发现错误,并将其添加到我的答案中。 – jfriend00
而且,你需要帮助的是什么问题?有什么不工作?哪行代码会出错? – jfriend00