css()没有为body标签设置background属性

时间:2016-02-26 09:23:36

标签: javascript java jquery html css

我在我的代码中使用了这些东西,但它们都没有用.Kindly建议我解决这个问题的任何其他方法。

// #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");
}

2 个答案:

答案 0 :(得分:0)

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

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

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

这必须包括在身体下方。

答案 1 :(得分: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");

}