有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javascript css()未设置正文标记的背景属性

我在我的代码中使用了这些东西,但没有一个有效。。请建议我解决这个问题的其他方法

// #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) 个答案

  1. # 1 楼答案

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

    $(body).css("background", "no-repeat fixed center -80px / cover !important");
    
    $(body).css("background-image", "url('${actionBean.backgroundImage}')");
    

    这必须包括在身体下面

  2. # 2 楼答案

    你也可以通过给你的身体类别提供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");
    

    }