我的饼干套装坏了

My cookie set is not working

本文关键字:坏了 饼干 我的      更新时间:2023-09-26

我的jQuery:

$(function() {
$("#change-background").on('submit', function(e) {
    var src = $(this).find("input").val();
    $.cookie("_usci",src);
    //NOT HERE$("body").css("background-image", 'url($.cookie("_usci"))';
});
    //BUT HERE!! otherwise it will not work
});

url需要在这些"或这些"内,但这样cookie就不会被很好地使用,我该如何解决这个问题?

你试过吗?:

$("body").css("background-image", 'url(' + $.cookie("_usci") + ')';

在css参数内使用字符串连接

$("body").css("background-image", 'url('+$.cookie("_usci")+')');
//don't forget to close your css call as Jonathan notes       ^