2016-02-26 62 views
1

我已经在我的代码中使用了这些东西,但没有一个能够正常工作。诚恳建议我使用任何其他方式解决此问题。css()不设置body标签的背景属性

// #1 
if ("${actionBean.backgroundImage}" != null){ 
    $(document.body).css("pointer-events", "none"); 
    $(document.body).css("cursor", "default"); 
    $(document.body).css("background", "url('${actionBean.backgroundImage}') no-repeat fixed center -80px/cover !important"); 
} 

// #2 
if ("${actionBean.backgroundImage}" != null){ 
    $('html, body').css("pointer-events", "none"); 
    $('html, body').css("cursor", "default"); 
    $('html, body').css("background", "url('${actionBean.backgroundImage}') no-repeat fixed center -80px/cover !important"); 
} 

// #3 
if ("${actionBean.backgroundImage}" != null){ 
    $("body").css("pointer-events","none"); 
    $("body").css("cursor","default"); 
    $("body").css("background", "url('${actionBean.backgroundImage}') no-repeat fixed center -80px/cover !important"); 
} 

// #4 
if ("${actionBean.backgroundImage}" != null){ 
    $(body).css("pointer-events", "none"); 
    $(body).css("cursor", "default"); 
    $(body).css("background", "url('${actionBean.backgroundImage}') no-repeat fixed center -80px/cover !important"); 
} 
+1

这是什么意思'$ {actionBean.backgroundImage}'。这是一个'选择器' – shu

+1

你的逻辑是有缺陷的; ''$ {actionBean.backgroundImage}“!= null'将永远不会成为'false',即使值是''''。 –

+0

$ {actionBean.backgroundImage} ... 它是一个Stripes变量....并且条件在这里不是假的... 我正在使用Stripes Framework ... –

回答

0

尝试使用单独的属性为背景,例如:

$(body).css("background", "no-repeat fixed center -80px/cover !important"); 

$(body).css("background-image", "url('${actionBean.backgroundImage}')"); 

,这必须被包括在主体的下方。

+0

是的,它的工作......但请解释我..如何正确地做事? 我在代码中的逻辑有问题吗? –

+0

它不工作:( –

0

,您还可以通过给ID,你的身体类使用这个....,并用它添加CSS

if ("${actionBean.backgroundImage}" != null){ 
    $("#bodyId").css("pointer-events", "none"); 
    $("#bodyId").css("cursor", "default"); 
    $("#bodyId").css("background", "url('${actionBean.backgroundImage}') no-repeat fixed center -80px/cover !important"); 

}