在IE 11上使用jquery不改变背景图像

时间:2017-07-08 10:11:10

标签: javascript jquery html css

亲爱的,我试图在点击时使用jquery更改div background-image,如下面的代码所示,除了IE之外,它在所有浏览器上工作.....请帮助

<div id="section1" class="section111">
        <div class="container">
            <div style="width: 100%; z-index: 999999999;" class="ServicesTitle">
                <p class="Main_TitaleServices">SERVICES & SOLUTIONS</p>
                <p class="slogan">Full Solutions for a Perfect Business   </p>
            </div>
            <div id="title-underline" style="margin-bottom: -30px;">
                <img src="../../App_Themes/ThemeEn/Images/title-underline.png">
            </div>
            <div class="firstrow">
                <div class="col-lg-3 divServices ">
                </div>
                </div>

        </div>
    </div>

这是脚本

<script>
$(function () {
$("#WebsiteDevelopment").click(function () {
    $("#section1").css("background-image", "url(/App_Themes/ThemeEn/Images/webdevelopment.jpg !important")
    /

});
$("#btnWebsiteDevelopment").click(function () {


    $("#section1").css("background-image", "url(/App_Themes/ThemeEn/Images/section1bg.png")

});
});
</script>

1 个答案:

答案 0 :(得分:0)

尝试设置background而不是background-image

<script>
$(function () {
$("#WebsiteDevelopment").click(function () {
    $("#section1").css("background", "url(/App_Themes/ThemeEn/Images/webdevelopment.jpg !important")
    /

});
$("#btnWebsiteDevelopment").click(function () {


    $("#section1").css("background", "url(/App_Themes/ThemeEn/Images/section1bg.png")

});
});
</script>

或使用纯javascript方法,

document.getElementById('section1').backgroundImage = "url('url(/App_Themes/ThemeEn/Images/webdevelopment.jpg !important')";