2016-02-26 46 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"); 

}