Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery字体大小调整脚本帮助(命名cookie)_Jquery - Fatal编程技术网

jQuery字体大小调整脚本帮助(命名cookie)

jQuery字体大小调整脚本帮助(命名cookie),jquery,Jquery,我正在使用jQuery文本大小调整脚本,从这里开始-。scipt如下所示: function fontSize(container, target, minSize, defSize, maxSize) { /*Editable settings*/ var minCaption = "Make font size smaller"; //title for smallFont button var defCaption = "Make font size default"; //title f

我正在使用jQuery文本大小调整脚本,从这里开始-。scipt如下所示:

function fontSize(container, target, minSize, defSize, maxSize) {
/*Editable settings*/
var minCaption = "Make font size smaller"; //title for smallFont button
var defCaption = "Make font size default"; //title for defaultFont button
var maxCaption = "Make font size larger"; //title for largefont button


//Now we'll add the font size changer interface in container
smallFontHtml = "<a href='javascript:void(0);' class='smallFont' title='" + minCaption +"'>" + minCaption + "</a> ";
defFontHtml = "<a href='javascript:void(0);' class='defaultFont' title='" + defCaption +"'>" + defCaption + "</a> ";
largeFontHtml = "<a href='javascript:void(0);' class='largeFont' title='" + maxCaption +"'>" + maxCaption + "</a> ";
$(container).html(smallFontHtml + defFontHtml + largeFontHtml);

//Read cookie & sets the fontsize
if ($.cookie != undefined) {
    var cookie = target.replace(/[#. ]/g,'');
    var value = $.cookie(cookie);
    if (value != null) {
        $(target).css('font-size', parseInt(value));
    } else {
        $(target).css('font-size', defSize);
    }
}

//on clicking small font button, font size is decreased by 1px
$(container + " .smallFont").click(function(){ 
    curSize = parseInt($(target).css("font-size"));
    newSize = curSize - 1;
    if (newSize >= minSize) {
        $(target).css('font-size', newSize);
    } 
    if (newSize <= minSize) {
        $(container + " .smallFont").addClass("sdisabled");
    }
    if (newSize < maxSize) {
        $(container + " .largeFont").removeClass("ldisabled");
    }
    updatefontCookie(target, newSize); //sets the cookie 

});

//on clicking default font size button, font size is reset
$(container + " .defaultFont").click(function(){
    $(target).css('font-size', defSize);
    $(container + " .smallFont").removeClass("sdisabled");
    $(container + " .largeFont").removeClass("ldisabled");
    updatefontCookie(target, defSize);
});

//on clicking large font size button, font size is incremented by 1 to the maximum limit
$(container + " .largeFont").click(function(){
    curSize = parseInt($(target).css("font-size"));
    newSize = curSize + 1;
    if (newSize <= maxSize) {
        $(target).css('font-size', newSize);
    } 
    if (newSize > minSize) {
        $(container + " .smallFont").removeClass("sdisabled");
    }
    if (newSize >= maxSize) {
        $(container + " .largeFont").addClass("ldisabled");
    }
    updatefontCookie(target, newSize);
});

function updatefontCookie(target, size) {
    if ($.cookie != undefined) { //If cookie plugin available, set a cookie
        var cookie = target.replace(/[#. ]/g,'');
        $.cookie(cookie, size);
    } 
}
}
所以在我的例子中,它总是被称为“包装器”。我一辈子都不知道如何为它指定一个唯一的名称


有人有什么想法吗?

嗯,包含的脚本确实使用目标名称作为cookie名称。我的建议是添加一个名为cookieName的新参数。新的签名将是:

function fontSize(container, target, minSize, defSize, maxSize, cookieName)
在脚本中的所有引用中,都使用该值。也就是说,更改例如:

updatefontCookie(target, newSize); //sets the cookie 
为此:

updatefontCookie(cookieName, newSize); //sets the cookie 
updatefontCookie(cookieName, newSize); //sets the cookie