Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.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
Javascript 我的曲奇饼集坏了_Javascript_Jquery_Html_Cookies - Fatal编程技术网

Javascript 我的曲奇饼集坏了

Javascript 我的曲奇饼集坏了,javascript,jquery,html,cookies,Javascript,Jquery,Html,Cookies,我的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

我的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       ^

您没有关闭
css()
调用中的括号。甚至SO中的编辑器也会通过将整个字符串显示为红色来告诉您。谢谢,可以工作,但我在自己的代码中也发现了一个错误谢谢,可以工作,但我在自己的代码中也发现了一个错误